Muut
May 26, 2015, 5:57am
1
So I have this:
{% include 'partials/nav-page.html' %}
Inside this partial is this:
page1-link / page1-preview / page1-gallery
I want to output this partial on several pages and change a variable inside the partial depending on the page, eg:
{% include 'partials/nav-page.html' variable=“1” %}
AND
page{{ variable }}-link / page{{ variable }}-preview / page{{ variable }}-gallery
Would output:
page1-link / page1-preview / page1-gallery
And
{% include 'partials/nav-book.html' variable=“2” %}
Would output:
page2-link / page2-preview / page2-gallery
Etc
This is a poor explanation, but is this possible?
Muut
May 26, 2015, 7:47am
2
I think the best will be using page headers. See:
http://learn.getgrav.org/themes/theme-vars#headers
So let’s say you have markdown page and you want that page to output variable “gallery”. In header you put:
variable: gallery
and in partial template file you just do:
{{ page.header.variable }}
This will output “gallery” variable name in your partial file. You can add as many variables as you want.
Muut
May 26, 2015, 7:59am
3
Oh yeah… thanks. I already use page headers in the page, just didn’t think about the partial being able to access them
Thanks for the help!
Muut
May 26, 2015, 8:01am
4
I also recommend taking look at twig include:
http://twig.sensiolabs.org/doc/tags/include.html
Maybe not really related to that topic but may help in the future
Muut
May 26, 2015, 7:54pm
5
Indeed, what you were asking could also be done like this:
{% include 'template.html' with {'some_variable': page.header.variable} %}
should you ever have need of it.
But like Karol explained, the header variables are available from partials too