1

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'}}" }}

Patsy Issa
  • 11,113
  • 4
  • 55
  • 74
Zigzagoon
  • 787
  • 6
  • 16
  • 1
    Possible duplicate of [Is it possible to nest helpers inside the options hash with handlebars?](http://stackoverflow.com/questions/14781916/is-it-possible-to-nest-helpers-inside-the-options-hash-with-handlebars) – Patsy Issa Apr 08 '16 at 08:00

2 Answers2

5

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.

locks
  • 6,537
  • 32
  • 39
-2

You can use,

{{my-component class="my-class" classNameBindings="isThisTrue:true-class:false-class"}}
acid_srvnn
  • 693
  • 8
  • 15