lundi 14 mars 2016

Ember.js 2.x: Call a Handlebars helper from another Handlebars helper

I'm trying to call a Handlebars helper from another Handlebars helper in my ember.js app and can't figure out how the blazes to do it in 2.x. For reference, I'm using Ember 2.4 with Ember-CLI.

There are several answers floating around that work in older versions; for example, the snippet below defines a Handlebars helper variant which tries to work some magic and then call Ember's built-in component helper...

import Ember from 'ember';

export function magicComponent(params) {
    // ...
    // do some magic here
    // ...

    return Ember.Handlebars.helpers['component'].apply(this, args); // Oops!
}

export default Ember.Helper.helper(magicComponent);

...but the line marked 'Oops!' is TypeErroring, since Ember.Handlebars.helpers is undefined in Ember 2.x. Welp.

Does anyone know how to go about programmatically calling a Handlebars helper (or setting up some sort of inheritance) in the latest Ember versions?

Aucun commentaire:

Enregistrer un commentaire