pushplaybang pushplaybang - 11 months ago 43
Javascript Question

Handlebars parse error on #each

I'm returning the following JSON object

"valmessage":"Your message has been sent successfully.",
"post_title":"handle test 2",
"post_content":"<p>giving it another go.<\/p>\n"},
"postdate":"Monday, March 17th, 2014",

and I'm getting the following error inside my handlebars template :

Uncaught Error: Parse error on line 23:
...replies}} {{ #each replies }
Expecting 'ID', 'DATA', got 'INVALID'

inside my tempalte I'm doing the following :

{{#if replies}}
{{ #each replies }}
<figure class="reply-author-img">
<img alt="" src="{{ avatar }}" height="96" width="96">
<div class="replycontentwrap">
<div class="reply-from">
<p class="reply-author">
<strong>{{ fullname }}</strong>
<span>{{ nickname }}</span>
<span class="replydate">{{ reply_date }}</span>
<div class="reply-content">{{ reply_content }}</div>
{{ /each }}

Replies is currently Null but it should be returning a set of objects when there are replies to the message, How would be the best way to 1) get this working and 2) approach this kind of data structure with handlebars.js ?

Answer Source

The error you are getting is a result of the fact that you have a space before the '#each' and '/each', so make it:

{{#each replies}}
    /* each stuff */