Skip to content

Commit b0e1e62

Browse files
author
jaylan
committed
bug fix #244
1 parent 5d27bb5 commit b0e1e62

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ process.env.NODE_ENV === "production"
185185

186186
A layout is simply a Handlebars template with a `{{{body}}}` placeholder. Usually it will be an HTML page wrapper into which views will be rendered.
187187

188-
This view engine adds back the concept of "layout", which was removed in Express 3.x. It can be configured with a path to the layouts directory, by default it's set to `"views/layouts/"`.
188+
This view engine adds back the concept of "layout", which was removed in Express 3.x. It can be configured with a path to the layouts directory, by default it's set to relative to `express settings.view` + `layouts/`
189189

190190
There are two ways to set a default layout: configuring the view engine's `defaultLayout` property, or setting [Express locals][] `app.locals.layout`.
191191

@@ -337,19 +337,21 @@ app.set('view engine', '.hbs');
337337

338338
**Note:** Setting the app's `"view engine"` setting will make that value the default file extension used for looking up views.
339339

340-
#### `layoutsDir="views/layouts/"`
340+
#### `layoutsDir`
341+
Default layouts directory is relative to `express settings.view` + `layouts/`
341342
The string path to the directory where the layout templates reside.
342343

343-
**Note:** If you configure Express to look for views in a custom location (e.g., `app.set('views', 'some/path/')`), you will need to reflect that by passing an updated path as the `layoutsDir` property in your configuration.
344+
**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` + `layouts/`, you will need to reflect that by passing an updated path as the `layoutsDir` property in your configuration.
344345

345-
#### `partialsDir="views/partials/"`
346+
#### `partialsDir`
347+
Default partials directory is relative to `express settings.view` + `partials/`
346348
The string path to the directory where the partials templates reside or object with the following properties:
347349

348350
* `dir`: The string path to the directory where the partials templates reside.
349351
* `namespace`: Optional string namespace to prefix the partial names.
350352
* `templates`: Optional collection (or promise of a collection) of templates in the form: `{filename: template}`.
351353

352-
**Note:** If you configure Express to look for views in a custom location (e.g., `app.set('views', 'some/path/')`), you will need to reflect that by passing an updated path as the `partialsDir` property in your configuration.
354+
**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.
353355

354356
**Note:** Multiple partials dirs can be used by making `partialsDir` an array of strings, and/or config objects as described above. The namespacing feature is useful if multiple partials dirs are used and their file paths might clash.
355357

lib/express-handlebars.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ function ExpressHandlebars(config) {
2424
utils.assign(this, {
2525
handlebars : Handlebars,
2626
extname : '.handlebars',
27-
layoutsDir : 'views/layouts/',
28-
partialsDir : 'views/partials/',
27+
layoutsDir : undefined, // Default layouts directory is relative to `express settings.view` + `layouts/`
28+
partialsDir : undefined, // Default partials directory is relative to `express settings.view` + `partials/`
2929
defaultLayout : undefined,
3030
helpers : undefined,
3131
compilerOptions: undefined,
@@ -191,8 +191,8 @@ ExpressHandlebars.prototype.renderView = function (viewPath, options, callback)
191191
var viewsPath = options.settings && options.settings.views;
192192
if (viewsPath) {
193193
view = this._getTemplateName(path.relative(viewsPath, viewPath));
194-
this.partialsDir = path.join(viewsPath, 'partials/');
195-
this.layoutsDir = path.join(viewsPath, 'layouts/');
194+
this.partialsDir = this.partialsDir || path.join(viewsPath, 'partials/');
195+
this.layoutsDir = this.layoutsDir || path.join(viewsPath, 'layouts/');
196196
}
197197

198198
// Merge render-level and instance-level helpers together.

0 commit comments

Comments
 (0)