玉模板引擎,如何使用layout.jade? [英] jade template engine, how to use layout.jade?
问题描述
mypage
我注意到我需要创建一个 layout.jade
和 mypage.jade
文件。如果我将代码放在 mypage.jade
中,则不显示,所以首先我必须填写 layout.jade
我的问题是,我如何在 layout.jade
里面引用我想要的内容。 例如在某个容器中加载 mypage.jade
的内容?我可以有不同的页面具有相同的布局吗?谢谢
http://expressjs.com/guide.html#view-rendering
如果您不想使用布局,您可以全局禁用它们:
应用程序。 set('view options',{
layout:false
});
如果您不这样做,默认情况下会启用该布局,Express将在your_view_folder中搜索标准布局/layout.jade
您可以为每个路线指定一个单独的布局:
res.render('page',{layout:'mylayout.jade'});
//你可以省略.jade如果你将视图引擎设置为jade
您的布局文件可以是:
doctype html
html(lang =en)
head
标题测试123
body
div!= body
请注意
修改:
这是应用程序中的一个实例:
应用程序文件(包含路由和配置):
https://github.com/alexyoung/nodepad/blob/master/app.js
布局文件:
https://github.com/alexyoung/nodepad/blob/master/views/layout.jade
I have a website in node.js; to create a page, say mypage
I noticed I need to create both a layout.jade
and mypage.jade
files. If I put code in mypage.jade
it is not displayed, so first I have to fill layout.jade
with the layout of the page.
My question is, how do I reference inside layout.jade
that I would like to load the content of mypage.jade
in a certain container, for example? Can I have different pages with the same layout? How can I do this?
Thanks
http://expressjs.com/guide.html#view-rendering
If you don't want to use layouts you can disable them globally:
app.set('view options', {
layout: false
});
If you don't do that layouts are enabled by default and Express searches for the standard layout in your_view_folder/layout.jade
You can specify a separate layout for each route though:
res.render('page', { layout: 'mylayout.jade' });
// you can omit .jade if you set the view engine to jade
Here's how your layout file could be:
doctype html
html(lang="en")
head
title Testing 123
body
div!= body
Note that body will be taken from "mypage.jade".
Edit:
Here's a real example in an application:
The application file (containing routes and configs):
https://github.com/alexyoung/nodepad/blob/master/app.js
The layout file:
https://github.com/alexyoung/nodepad/blob/master/views/layout.jade
这篇关于玉模板引擎,如何使用layout.jade?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!