My directory structrue looks like this:
/views/
|-- index.jade
|-- layout.jade
/account/
|-- login.jade
|-- register.jade
I have configured my view engine as follows:
app.set('view engine', 'jade');
Edit: I also have
app.set('views', __dirname + '/views');
My controllers look like:
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"});
});
With settings as described I am getting 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 am copying my layout.jade
file into the /account/
folder it works perfectly. Unfortunately this would make no sense since it forced me to have redundant layout files.
What am I missing?
Btw. this code snipplets are from AzzNomad's express/mongoose template which is very helpful in order to learn express with mongoose.
You need to put
extends ../layout
in your view under accounts since layout is not in the same folder.
You should also set views path, since it is in another directory besides application script.
app.set('views', __dirname + '/views');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With