C # double condition if

How to make a double condition {{#if person && Work}}? & & appears to be an invalid statement

+8
source share
2 answers

I do not think that handlebars supports multiple elements in the {{#if}} operator (related: The logical operator in handlebars.js {{#if}} is conditional ).

You can collapse multiple values ​​in your controller / view into one computed property and check this is the only value in the template. This new computed property will be updated when one of the original values ​​is updated:

App.ValuesTestController = Ember.Controller.extend({ value1: false, value2: true, value1and2: function(){ return this.get('value1') && this.get('value2'); }.property('value1', 'value2') }); 

Your template will 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> 
+8
source share

Even if @CraigTeegarden's answer is elegant, I found several cases where this workaround made my life easier and therefore made me happier:

 {{#if person}} {{#if work}} Yeah! {{/if}} {{/if}} 
+3
source share

All Articles