我将 assemble.io 用于一个简单的静态网站,但 {{title}} 标签存在问题。这是该问题的粗略概述。
这是我的layout.hbs:
<!DOCTYPE html>
<html>
<head>
<title>{{title}}</title>
</head>
<body>
<!-- the body tag is used to "pull in" content from pages -->
{{> body }}
</body>
</html>
我有 2 个用于数据的 json 文件:
foo1.json
{
"title": "Hello world I am title 1"
}
foo2.json
{
"title": "I am a different title"
}
我有 2 页:
foo1.hbs
{{#foo1 }}
{{> module1 }}
{{> module2 }}
{{> module3 }}
{{/foo1 }}
foo2.hbs
{{#foo2 }}
{{> module1 }}
{{> module2 }}
{{> module3 }}
{{/foo2 }}
我的gruntfile.js片段:
options: {
layout: "src/responsive/layouts/layout.hbs",
partials: 'src/responsive/modules/**/*.hbs',
data: 'src/responsive/data/**/*.json',
flatten: false
},
pages: {
expand: true,
cwd: 'src/responsive/pages',
src: '**/*.hbs',
dest: 'src/'
}
当我运行“grunt assemble”时,我没有得到页面标题。我认为这与上下文有关,就好像我将{{title}}
layout.hbs 更改为{{foo1.title}}
或者{{foo2.title}}
它可以工作但是两个页面在共享此模板时获得相同的标题。
如何使{{title}}
in layout.hbs 的上下文适用于传入的所有 json 文件?
一个。