Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Pass modular template variables to modules

Started by Pedro M 3 years ago · 1 replies · 602 views
3 years ago

Maybe I haven't read it in the Grav documentation or seen any code examples in any templates, but the question is: how can variables be passed from a modular page to its modules?

It doesn't seem like inheritance works here like it does in other templates (for example the default page which inherits the base template).
I have several modular templates that use the same code for some variables, and for them to work I have to define them in each template.
I can't use extend, I can't use include (the context is different), I can't use blocks, etc.
Maybe I'm not doing it right or it just can't be done.
Any suggestions?

👍 1
3 years ago

Any suggestions?

I have these common variables used in several modules templates:

TWIG
{% set blog = page.find(header_var('blog_url')|defined(theme_var('blog_page'))) %}
{% set override_style = theme_var('override_page_style')|defined(false) %}
{% set color_style = override_style ? theme_var('default_page_style')|default('primary') : page.parent.header.style|defined('primary') %}
{% set page_title = page.title %}
{% set show_title = page.header.show_title|defined(false) %}

How can I inherit from some partial template (like vars.html.twig), all these variables?
I've tried with all tags twig that influence in inheritance, like include, embed, block, use, etc, but no successfull results.
I think that inheritance vars between modules templates is not possible.

Suggested topics

Topic Participants Replies Views Activity
General · by themetman, 1 day ago
2 41 17 hours ago
General · by Hanns Mattes, 1 week ago
0 121 1 week ago
General · by Karmalakas, 1 week ago
2 185 1 week ago
General · by Hanns Mattes, 3 weeks ago
0 235 3 weeks ago
General · by Dima, 4 weeks ago
1 211 4 weeks ago