【发布时间】:2012-12-09 21:40:38
【问题描述】:
我刚刚在我的 express 项目中添加了另一个 Jade 模板,现在它呈现空白页面,带有空的 head 和 body 标签。它在 index.jade 扩展 layout.jade 时有效,但如果 layout.jade 扩展 logo.jade 则中断。控制台中没有错误。
这是项目的简化版本,运行良好。
app.js:
var express = require('express'),
http = require('http'),
path = require('path'),
request = require('request');
var app = express();
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view options', {'layout': false});
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
app.configure('development', function(){
app.use(express.errorHandler());
});
app.get('/', function(req, res){
res.render('index', {title: 'A Title'});
});
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
views/index.jade:
extends layout
block content
p Hello
views/layout.jade:
doctype 5
html(xmlns='http://www.w3.org/1999/xhtml')
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
body
h1= title
block content
添加 logo.jade 并从 layout.jade 扩展它会中断 Jade 渲染。
GET http://localhost:3000/
回复
200 OK
content-length: 0
修改视图/layout.jade:
extends logo
doctype 5
html(xmlns='http://www.w3.org/1999/xhtml')
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
body
block logo
h1= title
block content
新视图/logo.jade:
block logo
svg(xmlns='http://www.w3.org/2000/svg')
rect(
stroke='black'
fill='blue'
x='45'
y='45'
width='20px'
height='30px'
stroke-width='1')
【问题讨论】: