我正在使用HTML视图。 有这样的事吗? :
{{include head.html}}
index
</body>
</html>
答案 0 :(得分:0)
您正在寻找nodejs的模板引擎吗?
答案 1 :(得分:0)
我找到了解决方案。 的 server.js 强>
var hbs = require('hbs');
app.set('view engine', 'html');
app.engine('html', hbs.__express);
app.set('views', __dirname + '/views');
app.use(express.static(__dirname + '/public'));
hbs.registerPartials(__dirname + '/views/'); <-------- include folder
<强>的index.html 强> Index.html包括head.html,如下所示:
{{> head}}
index
</body>
</html>
答案 2 :(得分:0)
你正在寻找的是一个模板引擎,因为你提到{{ }}
标签我假设你正在使用Hogan.js
aka胡子(javascript版本)。
可以找到文档here,您正在寻找的是partials部分。
请注意,默认快递应用程序(如果选择hogan)随hjs模块一起安装,该模块不支持部分,您需要安装hogan-express模块并替换它们。
部分看起来像这样:
{{> head}}
index
</body>
</html>
部分是从get或post对象发送的,如下所示:
res.render('index.html', {
partials: {
head: 'partials/head.html'
}
});
答案 3 :(得分:-1)
如果你不想使用ejs或jade等,你可以用jquery来做。将此代码放在index.html
中<html>
<head>
<title></title>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(function(){
$("#header").load("header.html");
$("#footer").load("footer.html");
});
</script>
</head>
<body>
<div id="header"></div>
<!--Remaining section-->
<div id="footer"></div>
</body>
</html>