I'm Trying to create a custom "if_eq" helper for a Handlebars / Ember application. The helper is called with the following syntax: {{#if_eq item.name 'bob'}}, but is receiving 2 string values to compare (literally 'item.name' and 'bob'), instead of the value of "item.name" in the context it was called. Wondering what I might be doing wrong. Thanks!
Relevant code snippets are listed below and also created a jsbin to illustrate the problem here
Helper Code
Handlebars.registerHelper('if_eq', function(a, b, opts) {
console.log( "Comparing ", a, b);
if(a == b)
return opts.fn(this);
else
return opts.inverse(this);
});
Template code
<ul>
{{#each item in model}}
{{#if_eq item.name 'bob'}}
<li>We have a bob here!</option>
{{else}}
<li>A non-bob</li>
{{/if_eq}}
{{/each}}
</ul>
Aucun commentaire:
Enregistrer un commentaire