Skip to content

Instantly share code, notes, and snippets.

@srivathsapv
Created August 18, 2014 06:58
Show Gist options
  • Save srivathsapv/5dcebf41d528b7979ea9 to your computer and use it in GitHub Desktop.
Save srivathsapv/5dcebf41d528b7979ea9 to your computer and use it in GitHub Desktop.
Specifying multiple views for Express 4.x
var enableMultipleViewFolders = function(express) {
var eView= express.get('view');
var lookupProxy = eView.prototype.lookup;
eView.prototype.lookup = function (view) {
if (this.root instanceof Array) {
var opts = {};
var matchedView = null,
roots = this.root;
for (var i=0; i<roots.length; i++) {
this.root = roots[i];
matchedView = lookupProxy.call(this, view);
if (exists(matchedView)) break;
}
return matchedView;
}
return lookupProxy.call(eView, view)
};
}
enableMultipleViewFolders(app);
app.set('views', [pathToView1, pathToView2]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment