Question

Which file do I insert my Handlebars.registerHelper into?

Example. At the bottom of my object's controller/view/model/etc.

The ember docs (http://emberjs.com/guides/templates/writing-helpers/) say to insert it into my Javascript, but being that 90% of my project is javascript, it doesn't narrow my search.

Here's the helpers i want to insert into my object called 'Doc'

Handlebars.registerHelper('ifCond', function(v1, v2, options) {
  if(v1 === v2) {
    return options.fn(this);
  }
  return options.inverse(this);
});
Was it helpful?

Solution

You can toss it in any javascript file included after Handlebars and EmberJS has been inserted, you can just create any random js file and include it after Handlebars and EmberJS in the page. That is an invalid helper for two reasons though.

  1. You register helpers using Ember.Handlebars.registerBoundHelper(...) or Ember.Handlebars.helpers http://emberjs.com/api/classes/Ember.Handlebars.html#toc_simple-example

  2. helpers with blocks won't work (it will look like it works the first time, but when one of the values changes you'll get an error) http://emberjs.com/api/classes/Ember.Handlebars.html#toc_use-with-blocks-not-supported

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top