I implemented a script that I need on some of my blog posts, and that works great. I simply add
tinySlider: true
inside my Front matter and in my footer add the script in an If-statement.
My problem is that, I also want index.html…the one that holds the summaries of all my posts to also have this script. Can I populate the same .Props.tinySlider somehow?
I tried this, but Hugo doesnt like it:
{{ .Params.tinySlider = true }}
/content/posts/bla/index.md
/content/posts/bla2/index.md <-- this file has the frontmatter variable?
/content/posts/bla3/index.md
/content/posts/bla4/index.md
/content/posts/bla5/index.md
And then in the footer of the page something with that one (or more) page(s) where the variable is set?
Research and learn about scratch. It’s a bit more advanced. You collect stuff and reuse later.
A specific use-case would be interesting so we can wrap our heads around it. You could also just get the page object of the current page and then iterate through it and see if there is anything in the frontmatter in each one in your footer template. But then you might have lots of unused loops depending on the page size.
The other way around. I have this page C:\hugo_blog\themes\kiss\layouts\index.html <-- I want to set variable here
and I have C:\hugo_blog\themes\kiss\layouts\partials\footer.html <-- where the script is added on condition
PS: It works already like this:
C:\hugo_blog\content\posts\blogPost1.md <-- I set the variable here
C:\hugo_blog\content\posts\blogPost2.md <-- I dont set it here
C:\hugo_blog\content\posts\blogPost3.md <-- I set the variable here
UPDATE: The .Scratch solution worked! Very handy feature, thanks man!