Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow array of view directories #278

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion lib/express-handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,28 @@ ExpressHandlebars.prototype.renderView = function (viewPath, options, callback)
// to compute the view's name. Layouts and Partials directories are relative
// to `settings.view` path
var view;
var viewsPath = options.settings && options.settings.views;
// ************************************ ORIGINAL CODE ************************************ //
// expects a string for the views path configured in app.set("views", "the_path...")
// var viewsPath = options.settings && options.settings.views;
// ************************************ ORIGINAL CODE ************************************ //

// ************************************ PROPOSED CHANGE ************************************ //
// proposed change that allows an array of "views" directories to be passed in to app.set(...)
// will loop through the array and the last matching in the array will be used as the directory
// order of directories is important
var viewsPath = (function (_viewsPath, _viewPath) {
// if we have a string for the "views" directory return it
if (typeof _viewsPath === 'string') return _viewsPath;
var result;
var _viewPathDir = _viewPath.substring(0, _viewPath.lastIndexOf('/'));
_viewsPath.forEach(dir => {
if (dir === _viewPathDir && path.relative(dir, _viewPath).split('.').length > 1) {
result = dir;
}
});
return result;
})(options.settings && options.settings.views, viewPath);
// ************************************ PROPOSED CHANGE ************************************ //
if (viewsPath) {
view = this._getTemplateName(path.relative(viewsPath, viewPath));
this.partialsDir = this.partialsDir || path.join(viewsPath, 'partials/');
Expand Down