I wanted to create a simple Handlebars helper to output the JSON representation of bound variable (file: app/helpers/json.js
):
import Ember from 'ember';
export function json(input) {
return JSON.stringify(input);
}
export default Ember.Handlebars.makeBoundHelper(json);
I would then use this helper in the Dummy app's application.hbs
like so:
{{json myArray}}
Unfortunately when I do this I get the following error:
Uncaught Error: Handlebars error: Could not find property 'json' on object
I guess there's something going wrong with the resolver ... and I suspect it's related to the fact that I'm using the Dummy app within an addon. I did try and move the helper to /tests/dummy/app/helpers
with the hope that this would fix it but it seems to have no impact on the error message.
Custom helpers need to have a dash in their name to be loaded automatically:
Limiting automatically-loaded helpers to those that contain dashes is an explicit decision made by Ember. It helps disambiguate properties from helpers, and helps mitigate the performance hit of helper resolution for all bindings.
There’s an explanation there of how you can load a non-dashed helper if you need to. For your example, you would need to add this to app.js
:
import jsonHelper from './helpers/json';
Ember.Handlebars.registerBoundHelper('json', jsonHelper);