如何在node.js中实现jade模板的inheritance

我在同一个文件夹中有两个玉模板,就像:

|__layout.jade |__content.jade 

而layout.jade是父模板,content.jade将inheritance它:所以在layout.jade

 doctype 5 html(lang="en") head title= title body block content 

content.jade

 extends layout block content h1 this is frome nested template 

但是,当我运行它时,inheritance不起作用,它只显示父模板的内容

所以我的代码有什么问题?

确保在content.jade包含关键字“append”。

 extends layout block append content h1 this is from nested template 

更多关于这里。

这可能是一个完全的红鲱鱼,但我注意到你的两个文件似乎有不一致的缩进(至less在上面粘贴)。

如果你纠正这个问题,它会工作吗?

我有一个类似的问题,尝试堆栈溢出/ Jade文档node.js的各种答案。

在你的app.js文件中检查以下内容..

1)检查视图引擎设置为玉(现在改名为帕格):

 app.set("view engine", "jade"); 

2)设置视图文件夹(即你保存你的模板/视图文件):

 app.set("views", __dirname + "/views"); 

3)将布局设置为false:

 app.set('view options', { layout: false }); 

4)如果你使用express,检查你是否正在渲染正确的文件

 app.get("/", function(req, res){ res.render("contents.jade"); }); 

希望有所帮助

我testing了你的代码,没关系,你想尝试更新版本的node.js和jade吗?