I am trying to write a conditional if statement helper for Handlebars.js. Essentially, I want to put an "active" class on a link if it is the Apply Now
page.
Helper:
Handlebars.registerHelper('isApplyNow', function(block) {
if(this.title == "Apply Now") {
return block(this);
} else {
return block.inverse(this);
}
});
And Template:
<ul>
{{#each pages}}
<li>
{{#isApplyNow}}
<a href="{{url}}" class ='active'>{{this.title}}</a>
{{else}}
<a href="{{url}}">{{this.title}}</a>
{{/if}}
</li>
{{/each}}
</ul>
But, I am getting a very bare-bones javascript error:
Uncaught [object Object] in handlebars-1.0.0.beta.2.js:595
Can anyone see if I am writing this improperly?
Thanks!
Referenced articles:
Calling Helper Within If Block in Handlebars Template
http://thinkvitamin.com/code/handlebars-js-part-2-partials-and-helpers/