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

Creating subexpressions

A subexpression, as the name suggests, is an expression contained in another expression, which takes the following signature:

   {{outer-helper (inner-helper 'arg1') 'arg2'}}

Here's an example that implements a Number.toFixed helper:

Ember.Handlebars.registerHelper('to-fixed', function(num, decimals) {
  return new Ember.Handlebars.SafeString(
    num.toFixed(decimals)
  );
});

This can be used inside a link-to helper as:

  {{#link-to 'checkout' (to-fixed cart.total)}}
  checkout
  {{/link-to}}

This will result in something like the following:

   <a href='#/checkout/10.10'>checkout</a>

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