Since the introduction of HTMLBars in Ember, you've been able set attribute on elements in templates using boolean properties.
Here's the example from their docs located at http://guides.emberjs.com/v1.12.0/templates/binding-element-attributes/
Template:
<input type="checkbox" disabled={{isAdministrator}}>
HTML Output:
<input type="checkbox" disabled>
I'm trying to determine if their is a way to do the inverse. With this example, I want to set disabled only if isAdministrator is false.
Here's what I tried that does not work:
<input type="checkbox" disabled={{!isAdministrator}}>
That always results in disabled being applied regardless of the value of `isAdministrator.
In somecontroller.js:
var isABoolean = false;In sometemplate.hbs:
<button disabled={{!isABoolean}}>Do Stuff Only if isABoolean is true</button>
In the output.html
<button disabled>Do Stuff Only if isABoolean is tru</button>
I wrote up a little example of two approaches to solve this: http://ember-twiddle.com/245f05c2105f92768d04.
TLDR: You cannot have arbitrary expressions in HTMLBars/Handlebars such as
!. There are two good approaches to this problem, a computed macro and anothelper. Limiting arbitrary expressions in handlebars is by design as it it would encourage logic to leak into templates.