Nodejs包含其他视图? [英] Nodejs Include Other Views?
问题描述
我正在使用HTML视图。
有这样的东西吗? :
I am using html views. Is there a something like this? :
{{include head.html}}
index
</body>
</html>
推荐答案
您正在寻找的是模板引擎,因为你提到了 {{}}
标签我假设你正在使用 Hogan.js
aka mustache(javascript版本) 。
What you are looking for is a templating engine, since you mentioned the {{ }}
tags I am assuming you are using Hogan.js
aka moustache(the javascript version).
The documentation can be found here and what you are specifically looking for is the partials section.
请注意,默认快递应用程序(如果选择hogan)随hjs模块一起安装不支持partials,你需要安装hogan-express模块并替换它们。
Please note, the default express app(if you select hogan) comes installed with the hjs module which does not support partials, you will need to install the hogan-express module and replace them.
部分看起来像这样:
{{> head}}
index
</body>
</html>
部分是从get或post对象发送的,如下所示:
Partials are sent from a get or post object like so:
res.render('index.html', {
partials: {
head: 'partials/head.html'
}
});
这篇关于Nodejs包含其他视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!