lundi 25 mai 2015

Registering Handlebars string comparison helper in Ember.js not working

I'm trying to implement a string comparison helper in my ember app and I keep getting this error :

Uncaught Error: Assertion Failed: A helper named if_eq could not be found

I can't believe it's that complicated to compare 2 strings together, it should be a basic but seems like it's not the case. So where am I wrong? Should I use something else to compare the strings?

Template :

{{#if_eq selectedConv.status 'opened'}}
  <button><span class="close">Close</span></button>
{{else}}
  <button><span class="close">Open</span></button>
{{/if_eq}}

Helper (directly in js file)

Handlebars.registerHelper('if_eq', function(a, b, opts) {
if(a == b) // Or === depending on your needs
    return opts.fn(this);
else
    return opts.inverse(this);
});




Aucun commentaire:

Enregistrer un commentaire