I have a basic handlebars helper file located in helpers/handlebars.js
:
var hbs = require('express-handlebars');
hbs.registerHelper("inc", function(value, options) {
return parseInt(value) + 1;
});
Unfortunately, I am unable to utilize the {{#inc}}
helper because I forgot to pass it into the res.render()
function. Is there a way to automatically include and make all helpers within my file global?
edit:
After implementing @1cgonza's solution, I encountered the following error:
hbs.registerHelper("inc", function(value, options) {
^
TypeError: undefined is not a function
This error occurs when running the application. Below is an excerpt from app.js
:
var engine = require('express-handlebars');
require('./helpers/handlebars.js')(engine);
app.engine('hbs', engine({defaultLayout: 'layout', extname: 'hbs'}));
app.set('view engine', 'hbs');
Any suggestions on how to resolve this issue?