Skip to content
● Grav 2.2 is out: 2x faster cold starts and 96% less memory on big sites. Read the announcement →

Pass modular template variables to modules

Started by Pedro M 3 years ago · 1 replies · 497 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 Andy Miller, 1 week ago
0 121 1 week ago
General · by lynbor, 1 month ago
3 446 2 weeks ago
General · by lynbor, 3 weeks ago
7 577 2 weeks ago
General · by Harry, 2 weeks ago
0 167 2 weeks ago
General · by Old Man Umby, 1 month ago
2 312 4 weeks ago