Is there such a thing as a partial variable?

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” %}


page{{ variable }}-link / page{{ variable }}-preview / page{{ variable }}-gallery

Would output:

page1-link / page1-preview / page1-gallery


{% include 'partials/nav-book.html' variable=“2” %}

Would output:

page2-link / page2-preview / page2-gallery


This is a poor explanation, but is this possible? :smiley:

I think the best will be using page headers. See:

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.

Oh yeah… thanks. I already use page headers in the page, just didn’t think about the partial being able to access them :smiley:

Thanks for the help!

I also recommend taking look at twig include:
Maybe not really related to that topic but may help in the future :slight_smile:

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 :wink: