O'Reilly logo

Mastering Ember.js by Mitchel Kelonye

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing conditionals

Handlebars supports the if, if...else, unless, and unless...else conditionals. This means that we can render different portions of our templates based on specified conditions. They are block expressions that wrap template portions and usually begin and end with the {{# and {{/ template tags, respectively. For example, if the user has no stored contacts in the contacts template of the chapter sample, the application will transition into the contacts.new state to force the user to add one. Therefore, we need to display a placeholder string in the now blank left-hand side of the page. We do this by checking whether the passed contact list is indeed empty, as shown in the following code:

{{#if model.length}} ... {{else}} <h1>Create ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required