我是nodejs和jade的新手,并且正在阅读一个小型博客教程。我在没有扩展布局的情况下使翡翠页面正常工作。当我在index.jade中扩展布局时,页面将变为空白。知道这里发生了什么吗?
Layout.jade:
doctype 5
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
body
block content
index.jade(无
extends layout
)h1= locals.title
#articles
- each article in locals.articles
div.article
div.created_at= article.created_at
div.title
a(href="/blog/"+article._id)!= article.title
div.body= article.body
以及app.js中的呈现
app.get('/', function(req, res) {
articleProvider.findAll(function(error, docs) {
res.render('index.jade', { locals: {
title: "Blog",
articles: docs
}
});
});
});
最佳答案
不仅通过单独使用扩展来解决问题,还通过块来解决问题(请参见layout/block documentation)
extends layout
block content
h1= locals.title
代替
extends layout
h1= locals.title