I'd like to know if there is a built in way to extend Express.js's res.render function because, I'd like to pass a default set of "locals" to every template that is rendered. Currently I've written a small middleware that uses underscore.js's extend function to merge the default "locals" and the ones specific for that template:
app.use(function(req, res, next){
res.render2 = function (view, locals, fn) {
res.render(view, _.extend(settings.template_defaults, locals), fn);
};
next();
});
Is there a better way to do this?