I am initializing nunjucks
inside my express
app.js
file, and registering a custom addfilter
function in the same file just fine:
// get needed packages
const nunjucks = require('nunjucks');
// config view engine
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'html');
// set variable
const env = nunjucks.configure('views', {
autoescape: true,
express: app
});
// register custom helper
env.addFilter('shorten', function(str, count) {
return str.slice(0, count || 5);
});
However, I have a stack more of these addfilter
functions that I would like to add, but I don't want put them in my app.js
file. Specifically, I would like to put them here:
node-project/views/helpers/nunjucks_helpers.js
What would be the node express way to configure this package to register custom filters like this one in said other file?