# HTMLBars custom if helper

**URL:** <https://discuss.emberjs.com/t/htmlbars-custom-if-helper/6949>\
**Category:** Uncategorized\
**Created:** [December 18, 2014, 11:03am UTC](https://discuss.emberjs.com/t/htmlbars-custom-if-helper/6949 "2014-12-18T11:03:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gwenaelp](https://avatars.discourse-cdn.com/v4/letter/g/439d5e/32.png) [@gwenaelp](https://discuss.emberjs.com/u/gwenaelp)\
**Post date:** [December 18, 2014, 11:03am UTC](https://discuss.emberjs.com/t/htmlbars-custom-if-helper/6949/1 "2014-12-18T11:03:14Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![rwjblue](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/rwjblue/32/9411_2.png) [@rwjblue](https://discuss.emberjs.com/u/rwjblue)\
**Post date:** [December 18, 2014, 12:42pm UTC](https://discuss.emberjs.com/t/htmlbars-custom-if-helper/6949/2 "2014-12-18T12:42:33Z")

</div>

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](http://emberjs.jsbin.com/rwjblue/167/edit) as a starting point if you’d like…

---

<div class="post-metadata">

**Author:** ![gwenaelp](https://avatars.discourse-cdn.com/v4/letter/g/439d5e/32.png) [@gwenaelp](https://discuss.emberjs.com/u/gwenaelp)\
**Post date:** [December 18, 2014, 2:00pm UTC](https://discuss.emberjs.com/t/htmlbars-custom-if-helper/6949/3 "2014-12-18T14:00:03Z")

</div>

Hello,

Thank you for your answer!

I prepared a JSBin : [JS Bin - Collaborative JavaScript Debugging](http://emberjs.jsbin.com/fuzekegage/2/edit)

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… 😕

---

<div class="post-metadata">

**Author:** ![jschaftenaar](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jschaftenaar/32/10001_2.png) [@jschaftenaar](https://discuss.emberjs.com/u/jschaftenaar)\
**Post date:** [December 18, 2014, 7:16pm UTC](https://discuss.emberjs.com/t/htmlbars-custom-if-helper/6949/4 "2014-12-18T19:16:12Z")

</div>

See the bottom of the page [http://emberjs.com/api/classes/Ember.Handlebars.html#method\_makeBoundHelper](http://emberjs.com/api/classes/Ember.Handlebars.html#method_makeBoundHelper)

USE WITH BLOCKS NOT SUPPORTED

I believe you need to use a computed property

---

<div class="post-metadata">

**Author:** ![rwjblue](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/rwjblue/32/9411_2.png) [@rwjblue](https://discuss.emberjs.com/u/rwjblue)\
**Post date:** [December 18, 2014, 7:55pm UTC](https://discuss.emberjs.com/t/htmlbars-custom-if-helper/6949/5 "2014-12-18T19:55:51Z")

</div>

Correct. You need to use `Ember.HTMLBars.registerHelper` (note this is **not** bound so you have to subscribe and rerender when input param changes).
