My settings:
My structrue directory looks like this:
/views/ |-- index.jade |-- layout.jade /account/ |-- login.jade |-- register.jade
I configured my view engine as follows:
app.set('view engine', 'jade');
Edit: I also have
app.set('views', __dirname + '/views');
My controllers look like this:
app.get('/login', redirectIfLogined, function(req, res){ res.render('account/login', { title: "Login", redir: req.query.redir}); }); app.get('/register', redirectIfLogined, function(req, res) { res.render('account/register', { title: "Register"}); });
My problem
With the settings as described, I get a 500 error:
500 Error: failed to locate view "layout" at Function.compile (D:\dev\Azznomad\express-template\node_modules\express\lib\view.js:58:15) at ServerResponse._render (D:\dev\Azznomad\express-template\node_modules\express\lib\view.js:414:18) at ServerResponse.render (D:\dev\Azznomad\express-template\node_modules\express\lib\view.js:315:17) at ServerResponse._render (D:\dev\Azznomad\express-template\node_modules\express\lib\view.js:429:10) at ServerResponse.render (D:\dev\Azznomad\express-template\node_modules\express\lib\view.js:315:17) at D:\dev\Azznomad\express-template\controllers\accountController.js:6:13 at callbacks (D:\dev\Azznomad\express-template\node_modules\express\lib\router\index.js:272:11) at D:\dev\Azznomad\express-template\modules\middleware\account.js:27:9 at callbacks (D:\dev\Azznomad\express-template\node_modules\express\lib\router\index.js:272:11) at param (D:\dev\Azznomad\express-template\node_modules\express\lib\router\index.js:246:11)
As soon as I copy my layout.jade
file to the /account/
folder, it works fine. Unfortunately, this does not make sense, as it made me have redundant layout files.
What am I missing?
Btw. This is a snapshot of the code from AzzNomad express / mongoose template , which is very useful to learn how to express using mongoose.