Nodejs包含其他视图? [英] Nodejs Include Other Views?

查看:152
本文介绍了Nodejs包含其他视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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).

可以在这里找到文件。 / a>你正在寻找的是部分部分。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆