The existing lookupHelper
really only supports 3 helpers.
function lookupHelper(helperName) {
if (helperName === 'attribute') {
return this.attribute;
}
else if (helperName === 'partial'){
return this.partial;
}
else if (helperName === 'concat') {
return this.concat;
}
}
So would this need to be extended to do something more like this? I notice in the Ember helpers the helpers on env
function lookupHelper(helperName, env) {
if (helperName === 'attribute') {
return this.attribute;
}
else if (helperName === 'partial'){
return this.partial;
}
else if (helperName === 'concat') {
return this.concat;
}
else if (env.helpers[helperName]) {
return env.helpers[helperName];
}
}
or possibly this which would certainly make it easier to drop-in replace Handlebars?
var helpers = {
attribute: this.attribute,
partial: this.partial,
concat: this.concat
};
function registerHelper = function(name, fn) {
helpers[name] = fn;
}
function lookupHelper(helperName) {
return helpers[name];
}
or a mash of both? env
and this.helpers
?
function lookupHelper(helperName, env) {
return env.helpers[helperName] || helpers[name];
}
Or, quite possibly, I've enormously off-base from the outset and I'm missing how I'd get my own helpers in place and its already there.
@dbashford you have it pretty much correct. I suggest putting your helpers on
env.helpers
and havinglookupHelper
find them there. When you run a template, you will need to pass anenv
object withhelpers
and the built-inhooks
.The only difference is that hooks are called directly by the templates, and may have unique call signatures. Besides that the intended behavior is pretty much the same.