我试图在不使用系统渲染引擎的情况下将布局和内容放在express.js中的单独文件中。
我有layout.html和index.html,但我不知道如何正确地制作它。
以下是我的文件:
layout.html
{{> header}}
{{$content}}
default content
{{/content}}
{{> footer}}
index.html
{{<layout}}
{{$content}}
your content goes here
{{/content}}
{{/layout}}和我的脚本
var layout;
fs.readFile('layout.html','utf-8',function (err,view) {
layout = view;
});
fs.readFile('index.html','utf-8',function (err,view) {
var content = Hogan.compile(view);
var t = Hogan.compile(layout);
var s = t.render({},{'content':content});
res.send(s);
});我只得到布局默认值,而不是内容值。
发布于 2016-05-30 21:31:14
我找到了。
var content = Hogan.compile(index);
var t = Hogan.compile(layout);
var s = content.render({},{'layout':layout});
res.send(s);https://stackoverflow.com/questions/37526263
复制相似问题