How to configure paths for the layout to be rendered by ExpressJS
Following is the code in config/routes.js file
module.exports = function(app) {
app.get('/', function(req, res) {
res.render('login/login.jade', {
layout : 'layouts/login.jade',
title : 'Express'
});
});
};
Basically what I am trying is to render views/login/login.jade within views/layouts/login.jade.
But the path that expre开发者_运维技巧ss.js looks for to find the layout file is relative to views/login Following is the error I get.
**failed to locate view "layouts/login.jade", tried:
- ../msf_showcase_exp/views/login/layouts/login.jade
- ../msf_showcase_exp/views/login/../msf_showcase_exp/views/layouts/login.jade**
Is the anyway to specify in Express.js to search for the layout in views/layout. ?
this should work. just tried it (with node 0.4.11, express 2.4.6 and jade 0.15.4)
folders look like this
jadetest
|
-- app.js
|
-- package.json
|
-- public
|
-- route
| |
| -- router.js
|
-- views
|
-- index
| |
| -- index.jade
|
-- layouts
|
-- layout.jade
in app.js:
var express = require('express');
var app = module.exports = express.createServer();
var router = require('./route/router')(app);
in router.js
module.exports = function(app) {
app.get('/', function(req, res) {
res.render('index/index', {
title: 'Express',
layout: 'layouts/layout'
});
});
};
精彩评论