Is there a way to register helper functions to EJS templates, so that they can be called from any EJS template? So, it should work something like this.
app.js
<
I have another solution to this, and I think it has some advantages:
On your controller:
exports.index = function(req, res) {
// send your function to ejs
res.render('index', { sayHi: sayHi });
}
function sayHi(name) {
return 'Hello ' + name;
};
Now you can use sayHi function inside your ejs:
<%= sayHi('Nice Monkey!') %>
You can use this method to send modules to ejs, for example, you could send 'moment' module to format or parse dates.