ericf / express-handlebars

A Handlebars view engine for Express which doesn't suck.
BSD 3-Clause "New" or "Revised" License
2.31k stars 384 forks source link

layoutsDir must be specified if altering views location #86

Closed squaretone closed 10 years ago

squaretone commented 10 years ago

I'm not sure if this is a bug or if it just needs to be documented. If you change the location that Express looks for views (via app.set('views', myPath)), then you must also re-specify the same folder in express-handlebars config. For example.

This will incorrectly look for the main layout in the default location {current directory}/views/layouts:

var app = express();
var viewsPath = path.join(__dirname, 'customFolder', 'views');
app.set('views', viewPath);
app.engine('handlebars', exphbs({
    defaultLayout: 'main'
}));
app.set('view engine', 'handlebars');

Specifying the layoutsDir fixes the issue:

var app = express();
var viewsPath = path.join(__dirname, 'customFolder', 'views');
app.set('views', viewPath);
app.engine('handlebars', exphbs({
    defaultLayout: 'main',
    layoutsDir: viewsPath + '/layouts'
}));
app.set('view engine', 'handlebars');
ericf commented 10 years ago

Yeah these are simply configuration props with default string values, nothing fancy. I just used some sane defaults that fit with the idiomatic structure of Express apps: https://github.com/ericf/express-handlebars#layoutsdirviewslayouts

If you wanted to open a PR to add a note to the README about this, that would be great since the Express setting is disjointed from the Express Handlebars config.

ericf commented 10 years ago

Closing this now that #87 has been merged.