Node.js express:混淆ejs模板 [英] Node.js express: confuse about ejs template
问题描述
我将 ejs
模板文件放在视图
文件夹中,如:
I put my ejs
template file in views
folder like:
views
|
|--foo.html
|
|--layout.html
所以我配置我的ejs模板:
so I config my ejs template:
app.set('views', __dirname + '/views');
app.engine('html', require('ejs').renderFile);
我通过以下方式呈现我的 foo
I render my foo
template by this:
res.render('foo.html', {title: 'test'});
我想使用 layout.html
作为主版面模板,我还在 layout.html
中添加了<% - body%>
标签,但是没有没有工作,我看到的只是返回结束的 foo.html
。
I want use layout.html
as the master layout template, I also add <%- body%>
tag in layout.html
, but is doesn't work, what I saw is only return the ended foo.html
.
为什么 layout.html
不能是主版本?或者如何将其设置为主版式?
Why the layout.html
can't be the master layout?Or how can I set it to the master layout?
推荐答案
Ahah你刚刚被Express 3改变了布局管理。
官方示例: https://github.com/visionmedia/express / tree / master / examples / ejs
尚未更新。
Ahah you just got tricked by Express 3 change in layout management. The official example: https://github.com/visionmedia/express/tree/master/examples/ejs Has not been updated.
在Jade中,您现在必须使用块并扩展布局。
http://www.devthought.com/code/ use-jade-blocks-not-layouts /
In Jade you now have to use blocks and extend the layout. http://www.devthought.com/code/use-jade-blocks-not-layouts/
这篇关于Node.js express:混淆ejs模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!