Checking for home page?
How can I check in mustache if I'm on the homepage?
I want to do something different on the homepage, but the same on entries and the archive page. So using {{#entry.title}}...{{/entry.title}}
doesn't help me in this case.
Alex
Use custom metadata in your homepage file:
Homepage: yes
And in your template:
{{#entry.metadata.homepage}}
... will appear on your homepage
{{/entry.metadata.homepage}}
{{^entry.metadata.homepage}}
... will NOT appear on your homepage
{{/entry.metadata.homepage}}
Answered 6 days ago ·
Edit answer
I'm using the default entries.html
file for the homepage. If I try to add YAML front matter it just displays it like regular HTML. I tried adding the field in package.json
, but that didn't work either.
How can I add the metadata?
Alex
Answered 6 days ago · Edit answerAh I see, I assumed you were using a page with the following metadata:
Link: /
If you're just working within your template, create a new file index.html
and in package.json, set its URL to '/'
I don't follow. What would be the difference in creating index.html
? How would I create the homepage
variable?
I was hoping this might have worked, but alas :)
"entries.html": {
"homepage": "true",
"partials": {
"title": "{{{title}}}",
"description": "The latest on {{{title}}}"
}
},
```
Alex
Answered 6 days ago ·
Edit answer
A simpler option which only requires one template file, entries.html but assumes you have multiple pages of posts (which you do) is this:
{{#pagination}}
{{^previous}}
.. You are on the homepage
{{/previous}}
{{#previous}}
.. You are NOT on the homepage
{{/previous}}
{{/pagination}}
Answered 6 days ago ·
Edit answer
Just {{#pagination}}...{{/pagination}}
and {{^pagination}}..{{/pagination}}
seems to work fine! Thanks!
Alex
Answered 6 days ago · Edit answer
Newsletter
Get updates on Blot’s latest features and changes. Delivered every three months.