Continuing the discussion from How to add an Ember js helper?:
I am trying to add an Ember helper but having no luck. I get this error:
Uncaught Error: Assertion Failed: A helper named 'color-shade' could not be found
Below is my helper, color-shade.js …
import Ember from 'ember';
export function colorShade(params) {
//just placeholder code for now
return params[0] === params[1];
}
export default Ember.Helper.helper(colorShade);
Where did you put the helper? The location of the file matters.
I am defining the helper in:
assets/javascripts/discourse/helpers/color-shade.js
I am using the helper for a plugin outlet:
assets/javascripts/discourse/components/connectors/topic-category/topic-header.hbs
Try the extension .js.es6 – otherwise it’s not autoloaded.
Nice, good news is that A helper named 'color-shade' could not be found is no longer occurring.
Bad news is that I am now getting the error: Uncaught TypeError: Cannot read property 'helper' of undefined in regards to:
export default Ember.Helper.helper(colorShade);
Do I need to import Ember.Helper?
I think that’s the newer ember api. We’re on an older version. I’d suggest just looking at how the discourse helpers are defined and copying that.
Bingo! Defining my helper the following way did the trick:
import registerUnbound from 'discourse/helpers/register-unbound';
registerUnbound('color-shade', function(params) {
console.log(params);
});
Thanks!