Check for a value equals to in Ember Handlebar If block helper

user1338121 picture user1338121 · Jun 23, 2012 · Viewed 66.8k times · Source

How do we check for a value equality in ember.js's If-block helper?

{{#if person=="John"}}

How do we perform above in handlebars?

Answer

Jo Liss picture Jo Liss · Jun 24, 2012

The {{#if}} helper can only test for properties, not arbitrary expressions. The best thing to do in cases like this is therefore to write a property computing whatever conditional you want to test for.

personIsJohn: function() {
  return this.get('person') === 'John';
}.property('person')

Then do {{#if personIsJohn}}.

Note: If you find this too limiting, you can also register your own more powerful if helper.