How to do a double condition {{#if person && work}} ? The && seems not a valid operator
Double condition with #if
I don't believe handlebars supports multiple items in the {{#if}} statement (related: Logical operator in a handlebars.js {{#if}} conditional).
You could collapse the multiple values in your controller/view into a single computed property and check that single value in the template. This new computed property will update when either of the original values update:
App.ValuesTestController = Ember.Controller.extend({
value1: false,
value2: true,
value1and2: function(){
return this.get('value1') && this.get('value2');
}.property('value1', 'value2')
});
Your template would look like this:
<div>{{#if value1 }}value 1 true{{/if}}</div>
<div>{{#if value2 }}value 2 true{{/if}}</div>
<div>{{#if value1and2 }}value 1 and 2 true{{/if}}</div>
Even if the @CraigTeegarden's answer is the elegant one, I have found some cases where this workaround has made my life easier, and therefor it has made me happier:
{{#if person}}
{{#if work}}
Yeah!
{{/if}}
{{/if}}
© 2022 - 2024 — McMap. All rights reserved.