Sailsjs Adding Ejs Filters
In order to add custom ejs filters to a SailsJS application you could add them to the express
locals variable.
You need to modify your bootstrap.js
file:
module.exports.bootstrap = function(cb) {
var locals = {
siteTitle: 'LinkPin Pow',
filters: {
getTagLabels: function(tags){
return (tags || []).map(function(t){
return t.label;
}).join(', ');
}
}
}
sails.util._.extend(sails.hooks.http.app.locals, locals);
// It's very important to trigger this callback method when you are finished
// with the bootstrap! (otherwise your server will never lift, since it's waiting on the bootstrap)
cb();
};
Then, in your view, you should call it as follows:
<%=: link.tags | getTagLabels %>