Closed ahnbizcad closed 8 years ago
I don't think either Emblem or Handlebars supports arbitrary expressions in templates. The best short-term approach is probably to create a computed property.
{
menuItems: ['apple', 'banana', 'cucumber'],
selectedMenuItem: 'apple',
menuItemsState: function() {
var selected = this.get('selectedMenuItem');
return this.get('menuItems').map(function(item) {
return {
name: item,
active: item === selected
};
});
}.property('menuItems', 'selectedMenuItem')
}
However, the new HTMLBars helpers will solve this issue. Depending on when/how support is added in Emblem, you could probably do something along these lines:
export default Ember.Helper.helper(function equal(params) {
return params[0] == params[1];
}
li class=(equal string "desiredValue"):active plain text
There is a pull request that adds inline if syntax that works very similarly to your suggestion:
li class={ if (equal string "desiredValue") 'active' } plain text
I believe this was fixed in #234
You can do something like
But how can I do something like this?
I couldn't find anythign like this on the docs.