Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double condition with #if

Tags:

ember.js

How to do a double condition {{#if person && work}} ? The && seems not a valid operator

like image 719
fvisticot Avatar asked Jan 04 '13 00:01

fvisticot


1 Answers

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>
like image 149
CraigTeegarden Avatar answered Jan 01 '23 14:01

CraigTeegarden