I'm trying to format my dates using a handlebars registered momentjs helper inside an #each loop. The registered helper looks like this :
Handlebars.registerHelper('dateFormat', function(context) { if (window.moment) { return moment(Date(context)).format("MMM Do, YYYY"); }else{ return context; }; });
The handlebars loop looks like this
{{#each controller}}
{{{body}}}
{{{dateFormat date}}}
{{/each}}
The JSON that is being looped is in this
{ "idea":[ { "_id":"548eeebeda11ffbe12000002", "body":"cow", "tag":"cow", "date":"2014-12-15T14:22:54.088Z" }, { "_id":"548eeec2da11ffbe12000003", "body":"cow", "tag":"moose", "date":"2014-10-15T14:22:58.947Z" } ] }
So the problem that I'm having is that it loops just fine it just doesn't evaluate the helper correctly.
The results that I'm getting look like this
cow Dec 15th, 2014
cow Dec 15th, 2014
The dates are always the same.
Its should to look like this
cow Dec 15th, 2014
cow Oct 15th, 2014
I got it working using this.get('date');