'Is there a way to register a global helper file for Handlebar.js?
I use Handlebar.js to render a template.
function renderTemplate(data, templateName) {
const html = fs.readFileSync(`${__dirname}/templates/template2.hbs`, 'utf8')
//register one helper
hbs.registerHelper("formatName", function () {
return "This is my jam"
});
const template = hbs.compile(html)
const rendered = template(data)
return rendered
}
Now as you can see I can register a helper in the function. However, I might write 10-20 helpers. That way this function gets very 'bloated' en unnecessarily large. Is there a way to register a global helper.js file or something a like where I can put all my helpers?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
