Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ember if or statement

When using a conditional in ember, is it possible to have an OR?

{{#if foo OR bar}}

or

{{#if foo || bar}}

There doesn't seem to be anything on it in the docs.

like image 653
stevenspiel Avatar asked Jul 17 '14 18:07

stevenspiel


2 Answers

You should move the logic to your controller

App.SomeController = Em.Controller.extend({
  foo: true,
  bar: false,

  fooOrBar: Em.computed.or('foo', 'bar')
});

Leaving the template logic to a minimum

{{#if fooOrBar}}
like image 140
Kingpin2k Avatar answered Oct 18 '22 22:10

Kingpin2k


Use https://github.com/jmurphyau/ember-truth-helpers:

ember install ember-truth-helpers

Then you can say

{{#if (or foo bar)}}

Depending on your perspective, Kingpin2k's answer is a bit out of date. Previously, the community's understanding was that templates should be largely free of logic. Overtime, our viewpoint has shifted towards putting more declarative logic in templates-- ember-composable-helpers is a great example of this.

like image 27
Max Wallace Avatar answered Oct 18 '22 22:10

Max Wallace