Zigzagoon
Zigzagoon

Reputation: 825

"if" handlebar inside a component handlebar in Ember.js

In Ember, I know that I can include classes with if statements using the {{if}} handlebar. However, how can I do this inside a component handlebar?

For example, how can I do something like this:

{{myComponent class="my-class {{if isThisTrue 'true-class' 'false-class'}}" }}

Upvotes: 1

Views: 707

Answers (2)

acid_srvnn
acid_srvnn

Reputation: 693

You can use,

{{my-component class="my-class" classNameBindings="isThisTrue:true-class:false-class"}}

Upvotes: -2

locks
locks

Reputation: 6577

Since the curly braces can't be nested there is a syntax called nested helper to do so, and it works for most of the helpers like if, unless, concat, and family:

{{myComponent class=(concat "my-class " (if isThisTrue 'true-class' 'false-class'))}}

You have to use concat here since you're putting together a static and a dynamic portion of the string together.

Upvotes: 5

Related Questions