我正在使用Express@3.0.0rc2 + jade@0.2.3 + consolidate@0.5.0。当我渲染页面时,输出不是预期的。这是玉:
index.jade
extends ../../layouts/default
block headIncludes
link(href='/_widgets/search/index.css',rel='stylesheet')
block footerIncludes
script(type='text/javascript',src='/_widgets/search/index.js')
script(src='/views/site/home/js/index.js')
block content
header(class='jumbotron masthead')
div.inner
h1 Pricing Page
//Search
div.row-fluid
div(class='span12 centeredText',id='searchWidget')
div.row-fluid
div.span12
div.row-fluid
div.span12
div.row-fluid
div.span12
这是输出:
<extends>../../layouts/default</extends><block>headIncludes</block> link(href='/_widgets/search/index.css',rel='stylesheet') <block>footerIncludes</block> script(type='text/javascript',src='/_widgets/search/index.js') script(src='/views/site/home/js/index.js') <block>content</block> header(class='jumbotron masthead') div.inner h1 Pricing Page //Search div.row-fluid div(class='span12 centeredText',id='searchWidget') div.row-fluid div.span12 div.row-fluid div.span12 div.row-fluid div.span12
正如您所看到的,现在创建
,而不是像Jade一样评估Extends<extends>../../layouts/default</extends>
对于Block来说同样如此。
<block>headIncludes</block>
以下是我设置应用的方式:
app.js
....
var app = express()
require('./settings').boot(app, config, passport)
settings.js
var express = require('express')
, RedisStore = require('connect-redis')(express)
, url = require("url")
, cons = require('consolidate')
exports.boot = function(app, config, passport){
bootApplication(app, config, passport)
}
// App settings and middleware
function bootApplication(app, config, passport) {
app.set('showStackError', true)
app.use(express.static(__dirname + '/public'))
app.use(express.logger(':method :url :status'))
// set views path, template engine and default layout
app.configure(function () {
app.engine('jade', require('jade').renderFile)
app.set('views', __dirname + '/app/views')
app.set('view engine', 'jade')
app.set('view options', { layout: false })
// cookieParser should be above session
app.use(express.cookieParser())
// bodyParser should be above methodOverride
app.use(express.bodyParser())
app.use(express.methodOverride())
var redisURL = process.env.REDISTOGO_URL || config.redis
console.log(redisURL)
var redisUrl = url.parse(redisURL),
redisAuth = redisUrl.auth.split(':');
app.set('redisHost', redisUrl.hostname);
app.set('redisPort', redisUrl.port);
app.set('redisDb', redisAuth[0]);
app.set('redisPass', redisAuth[1]);
app.use(express.session({
secret: '......',
cookie: { maxAge: new Date(Date.now() + 360000)}, //1 Hour
store: new RedisStore({
host: app.set('redisHost'),
port: app.set('redisPort'),
db: app.set('redisDb'),
pass: app.set('redisPass')
})
}))
app.use(passport.initialize())
app.use(passport.session())
app.use(express.favicon())
require('./config/customMiddleware').boot(app)
// routes should be at the last
app.use(app.router)
// assume "not found" in the error msgs
// is a 404. this is somewhat silly, but
// valid, you can do whatever you like, set
// properties, use instanceof etc.
app.use(function(err, req, res, next){
// treat as 404
if (~err.message.indexOf('not found')) return next()
// log it
console.error(err.stack)
// error page
res.status(500).render('500')
})
// assume 404 since no middleware responded
app.use(function(req, res, next){
res.status(404).render('404', { url: req.originalUrl })
})
})
app.set('showStackError', false)
}
这对我来说似乎很奇怪,因为Jade看起来有点编译,只是没有预料到的那样。有什么想法吗?
答案 0 :(得分:0)
您需要将jade
更新为较新版本 - 至少0.16.0
template inheritance block
和extends
。
当前版本为0.27.7
。
您可能还想更新express
,rc
不再是{{1}}。