How to use Custom helpers in ember-app-kit?


#1

i have this custom helper in app/helpers/moment-date.js

    var momentDate = Ember.Handlebars.helper('momentDate',function(date) {
      return moment(date).fromNow();
    });
export default momentDate;

and the following handlebars in template:

{{momentDate creationDate}}

but it cause this error:

Uncaught Error:  Handlebars error: Could not find property 'momentDate' on object <(subclass of Ember.ObjectController):ember316>. 

how ember-app-kit resolves custom helpers in app/helpers??


#2

Well if you look in the ember-app-kit-example-with-bloggr-client you see virtually the same helper but it is a Bound Helper. Syntax below and at the link.

var formatDate = Ember.Handlebars.makeBoundHelper(function(date) {
  return window.moment(date).fromNow();
});

export default formatDate;

#3

If your using a build of ember with the container-renderables feature, the way your defining the helper should be fine; but you should reference it in templates using the dasherized name (i.e. moment-date). See issue 63 for some relevant discussion.

For using a build without the container-renderables feature you need to actually import the helper module somewhere. For an example have a look at fire-up-ember-app-kit.


#4

I tested it and registerBoundHelper but dont work


#5

Yes i knew this and when i use the import in my controller it works same as :

import price from 'appkit/helpers/price';  

in fire-up-ember-app-kit. But i wanted to know how can ember automatically resolve this.