O'Reilly logo

Ember.js Cookbook by Erik Hanchett

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

Working with conditionals in templates

Using conditionals is fundamental to using Ember's templating engine. In the following recipes, we'll take a look at conditionals and how they work with templates.

How to do it...

Let's take a look at a simple example that displays text if some property is true.

  1. Create a new project and generate a new controller called conditional. Run this command in the root of the application folder to create controller and template:
    $ ember g controller conditional
    $ ember g template conditional
    

    This will create the conditional controller.

  2. Update the router.js file with the new conditional route:
    // app/router.js
    …
    Router.map(function() {
      this.route('conditional');
    });

    This will add a new conditional route. To access this route ...

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