Helper is broken in Ember 1.10

I used the special Handlebars helper to extend the functionality of the if block.

In Ember 1.10, this no longer works, since there is no Ember.Handlebars.bind property that allows binding to the property ....

Ember.Handlebars.registerHelper('ifCond', function (a, b, options) { return Ember.Handlebars.bind.call(options, contexts[0], a, options, true, function(result) { return result === b }); }); 

Usage will be:

 {{#ifCond property "value"}} {{some-other-component}} {{else}} something other... {{/ifCond}} 

but this returns the error "Unable to read property" call to "undefined"

Is there a way that I can bind to passed properties in helper? I cannot use registerBoundHelper because it does not support child blocks ... I wanted to use the Component instead of the helper, but then I can not use the {{else}} block ...

This assistant solution was previously taken from the Boolean operator in handlebars.js {{#if}} conditional

+3
source share
1 answer

I really managed to find a way to do this, so I will write the answer to my question ...

Instead of using undocumented hacks, I used the proposed change: https://github.com/emberjs/ember.js/issues/10295

So my assistant looks like this:

 Ember.Handlebars.registerBoundHelper('isSame', function(value1, value2) { return value1 === value2 }); 

and use:

 {{#if (isSame property "value")}} {{some-other-component}} {{else if (isSame property "otherValue"}} something other... {{else}} something other... {{/if}} 
+4
source

Source: https://habr.com/ru/post/982772/


All Articles