9

我将 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 文件?

一个。

4

1 回答 1

3

@Adi 我在这里设置了一个包含您描述的结构的存储库。

我刚刚在 layout.hbs 中更改了这段代码,它按预期工作。

<!DOCTYPE html>
<html>
  <head>
    <title>{{page.title}}</title>
  </head>
  <body>
    <!-- the body tag is used to "pull in" content from pages -->
    {{> body }}
  </body>
</html>

如果您有我们可以查看的 repo,它可能有助于追踪问题。

希望这可以帮助。

于 2014-07-28T04:13:34.360 回答