lundi 2 mars 2015

HTMLBars helper with inverse

I'm trying to build a helper w/ an else block.


I can only find handlebars examples. They show that options.inverse is a function, but for my HTMLBars helper the options.inverse is an object. (e.g not callable)


template code:



{{#can 'audit' 'user' }}
AUDIT_LINK_PLACEHOLDER
{{else}}
NO_AUDIT_LINK
{{/can}}


helper code:



Ember.Handlebars.registerHelper("can", function(verb, noun, options) {
var abilities = this.container.lookup('controller:application').currentAbilities;
var sub_ability = abilities[noun] || {};
var fn = (sub_ability[verb] || sub_ability['manage']) ? options.fn : options.inverse;
return fn(this);
});




Aucun commentaire:

Enregistrer un commentaire