HTMLBars: bound block helper

Hi,

With handlebars i have this helper:

Ember.Handlebars.registerHelper('isGranted', function(action,options) {
    return Ember.Handlebars.bind.call(options.contexts[0], "user.actions", options, true, function(result) {
        return App.userManager.get("current").isGranted(action);
    });
});

I know it doesn’t deserve a beauty price, but it worked.

With htmlbars, the bind.call method doesn’t work anymore. How can i make this work with htmlbars? What i want: – template —

<h1>Nice template </h1>
{{#isGranted 'specialRole'}}
  You have access
{{else}}
  nop
{{/isGranted}}

this should ask user.isGranted(); to check the access, but i want to bind it to user.actions, because if the actions change, it should check again.

Any idea’s how to fix this helper in ember 1.11.1 ?

Does somebody know an answer?

I was just dealing with this same issue. You need to use the new if syntax. {{#if (helper [arguments])}}

So register your helper with:

Ember.HTMLBars.makeBoundHelper(function(params){
  return App.userManager.get("current").isGranted(params[0]);
); 

Then use:

{{#if (isGranted 'specialRole')}}
  You have access
{{else}}
  nop
{{/if}}

That’s what worked for me anyways. Good luck!

1 Like