Hello,
I’m currently migrating a large code base to HTMLBars. I’m currently having trouble with a custom if helper I wrote.
{{#each arrayItem in controller.arrayOfItems}}
!!{{arrayItem.label}}!!
<br/>
{{#ifUserCanDisplayView arrayItem.value}}
**{{arrayItem.label}}**
{{/ifUserCanDisplayView}}
{{/each}}
Ember.HTMLBars.helper('ifCustom', function(params, hash, options, env) {
if(1)
return options.template.render(this, env, options.morph.contextualElement);
});
Actually, the generated html contains the part inside the if, but I cannot access anymore to the variable arrayItem.
So this is basically what I get:
!!labelX!!
****
!!labelY!!
****
Does anybody knows how it is possible with HTMLBars to bind the context outside the if helper inside it too? I’m quite lost with the new API…
Thanks in advance for your help!
rwjblue
December 18, 2014, 12:42pm
2
Would be easier to help if you provided a simple JSBin. Would you mind whipping one together?
You can use JS Bin - Collaborative JavaScript Debugging as a starting point if you’d like…
Hello,
Thank you for your answer!
I prepared a JSBin : JS Bin - Collaborative JavaScript Debugging
I actually realized I was using the prod version. With the debug version, there is one error message, but no html generated.
“Error: Assertion Failed: makeBoundHelper generated helpers do not support use with blocks”
I don’t know what are my options to pass through this problem. I saw that there are only BoundHelpers and ViewHelpers by inspecting Ember.HTMLBars object, but I can’t find an easy way to get some more information about it…
See the bottom of the page
http://emberjs.com/api/classes/Ember.Handlebars.html#method_makeBoundHelper
USE WITH BLOCKS NOT SUPPORTED
I believe you need to use a computed property
rwjblue
December 18, 2014, 7:55pm
5
Correct. You need to use Ember.HTMLBars.registerHelper
(note this is not bound so you have to subscribe and rerender when input param changes).