In my assemblefile.js I try to register a custom helper. The helper itself does work since i have it in use in a grunt project with assemble.
assemble: {
options: {
helpers: ['./src/helper/custom-helper.js' ]
}
}
In assemble 0.17.1 I tried it like this but it doesn´t work. Does anyone know how to do this?
app.helpers('./src/helper/custom-helper.js');
custom-helper.js:
module.exports.register = function (Handlebars, options, params) {
Handlebars.registerHelper('section', function(name, options) {
if (!this.sections) {
this.sections = {};
}
this.sections[name] = options.fn(this);
return null;;
});
};
assembleis built on top of thetemplatesmodule now, so you can use the.helperand.helpersmethods for registering helpers with assemble, which will register them with Handlebars. This link has more information on registering the helpers.Since the
templatesapi is used, you don't have to wrap the helpers with the.registermethod in your example. You can just export the helper function, then name it when registering with assemble like this:You may also export an object with helpers and register them all at once using the
.helpersmethod:When registering the object with the
.helpersmethod, the property keys are used for the helper names