# Use conditional helpers

**URL:** <https://discuss.emberjs.com/t/use-conditional-helpers/14559>\
**Category:** Uncategorized\
**Created:** [April 17, 2018, 10:06am UTC](https://discuss.emberjs.com/t/use-conditional-helpers/14559 "2018-04-17T10:06:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![belgoros](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/belgoros/32/16101_2.png) [@belgoros](https://discuss.emberjs.com/u/belgoros)\
**Post date:** [April 17, 2018, 10:06am UTC](https://discuss.emberjs.com/t/use-conditional-helpers/14559/1 "2018-04-17T10:06:50Z")

</div>

I tried to use an `if` helper as follows:

```auto
{{#if existingDaysIds.includes(weekday.id)}}
    <p>includes</p>
{{/if}}

```

and it failed:

```auto
emplate Compiler Error (TemplateCompiler) in .../templates/working-hours.hbs

Parse error on line 6:
...#if existingDaysIds.includes(1)}}      
-----------------------^
Expecting 'ID', got 'INVALID'

```

When I display `existingDaysIds` array:

```auto
<p>{{existingDaysIds}}</p>

```

it displays the number I’d like to check:

```auto
0,1,2,3,4,5,6

```

What’s wrong with that ?

---

<div class="post-metadata">

**Author:** ![lookingsideways](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/lookingsideways/32/13652_2.png) [@lookingsideways](https://discuss.emberjs.com/u/lookingsideways)\
**Post date:** [April 17, 2018, 10:49am UTC](https://discuss.emberjs.com/t/use-conditional-helpers/14559/2 "2018-04-17T10:49:53Z")

</div>

Handlebars will only work with values, it won’t run any code directly but you can use [helpers](https://guides.emberjs.com/v3.0.0/templates/handlebars-basics/#toc_helpers) to augment the basic functionality.

There could be two ways to do what you want depending on your requirements:

1. Add a computed property (CP) to your `working-hours` controller, something like:

2. Use an `includes` type helper in your template. [ember-composable-helpers](https://github.com/DockYard/ember-composable-helpers#contains) includes such a `{{contains}}` helper that you can use in a [handlebars sub-expression](https://guides.emberjs.com/v3.0.0/templates/handlebars-basics/#toc_nested-helpers).

Option 1 is usually preferable when you’re working with complex data or manipulations. Option 2 can be a nice way to be more declarative in your templates but beware of putting too much logic there, it can become difficult to reason about and unit test.

---

<div class="post-metadata">

**Author:** ![belgoros](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/belgoros/32/16101_2.png) [@belgoros](https://discuss.emberjs.com/u/belgoros)\
**Post date:** [April 17, 2018, 12:18pm UTC](https://discuss.emberjs.com/t/use-conditional-helpers/14559/3 "2018-04-17T12:18:15Z")

</div>

@lookingsideways: Thank you very much for such a detailed explanation, really useful for someone like me who is in the very beginning of his _Ember way_.
