Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ The string path to the directory where the partials templates reside or object w
* `dir`: The string path to the directory where the partials templates reside.
* `namespace`: Optional string namespace to prefix the partial names.
* `templates`: Optional collection (or promise of a collection) of templates in the form: `{filename: template}`.
* `rename(filePath, namespace)`: Optional function to rename the partials. Takes two arguments: `filePath`, e.g., `partials/template.handlebars` and `namespace`.

**Note:** If you configure Express to look for views in a custom location (e.g., `app.set('views', 'some/path/')`), and if your `partialsDir` is not relative to `express settings.view` + `partials/`, you will need to reflect that by passing an updated path as the `partialsDir` property in your configuration.

Expand Down
9 changes: 8 additions & 1 deletion lib/express-handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ ExpressHandlebars.prototype.getPartials = function (options) {
var dirPath;
var dirTemplates;
var dirNamespace;
var dirRename;

// Support `partialsDir` collection with object entries that contain a
// templates promise and a namespace.
Expand All @@ -64,6 +65,7 @@ ExpressHandlebars.prototype.getPartials = function (options) {
dirTemplates = dir.templates;
dirNamespace = dir.namespace;
dirPath = dir.dir;
dirRename = dir.rename;
}

// We must have some path to templates, or templates themselves.
Expand All @@ -79,6 +81,7 @@ ExpressHandlebars.prototype.getPartials = function (options) {
return {
templates: templates,
namespace: dirNamespace,
rename: dirRename,
};
});
}, this);
Expand All @@ -89,10 +92,14 @@ ExpressHandlebars.prototype.getPartials = function (options) {
return dirs.reduce(function (partials, dir) {
var templates = dir.templates;
var namespace = dir.namespace;
var rename = dir.rename;
var filePaths = Object.keys(templates);

var getTemplateNameFn = typeof rename === 'function'
? rename : getTemplateName;

filePaths.forEach(function (filePath) {
var partialName = getTemplateName(filePath, namespace);
var partialName = getTemplateNameFn(filePath, namespace);
partials[partialName] = templates[filePath];
});

Expand Down