I am using assemble.io for a simple static web site but am having issues with the {{title}} tag. Here is a rough overview of the issue.
Here is my 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>
I have 2 json files for data:
foo1.json
{
"title": "Hello world I am title 1"
}
foo2.json
{
"title": "I am a different title"
}
And I have 2 pages:
foo1.hbs
{{#foo1 }}
{{> module1 }}
{{> module2 }}
{{> module3 }}
{{/foo1 }}
foo2.hbs
{{#foo2 }}
{{> module1 }}
{{> module2 }}
{{> module3 }}
{{/foo2 }}
My gruntfile.js snippet:
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/'
}
When I run 'grunt assemble' I get no page title. I think this has something to do with context as if I change {{title}}
in layout.hbs to be {{foo1.title}}
or {{foo2.title}}
it works but then both pages get the same title as they share this template.
How can I make the context of {{title}}
in layout.hbs work for all json files being passed in?
A.
@Adi I setup a repo here containing the structure that you described.
I just changed this code in layout.hbs and it's working as expected.
<!DOCTYPE html>
<html>
<head>
<title>{{page.title}}</title>
</head>
<body>
<!-- the body tag is used to "pull in" content from pages -->
{{> body }}
</body>
</html>
If you have a repo we can look at, it might help track down the issue.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With