Problem

You have portions of your views layer that use the same or similar HTML in many places.

Solution

Write a custom Handlebars helper that can be called from any template and gets updated when the model changes.

Discussion

  1. <script type="text/x-handlebars">
  2. $ {{dollar model}}
  3. </script>
  1. App = Ember.Application.create();
  2. App.ApplicationRoute = Em.Route.extend({
  3. model: function() {
  4. return 980; // cents
  5. }
  6. });
  7. Ember.Handlebars.registerBoundHelper('dollar', function(cents) {
  8. var dollar = Math.floor(cents / 100);
  9. return dollar;
  10. });

JS Bin