Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Pass modular template variables to modules

Started by Pedro M 3 years ago · 1 replies · 463 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 jeremycherfas, 1 week ago
4 182 2 days ago
General · by lynbor, 6 days ago
2 124 3 days ago
General · by Old Man Umby, 1 week ago
1 100 1 week ago
General · by Sebastian, 2 weeks ago
1 124 2 weeks ago
General · by Andy Miller, 3 weeks ago
0 248 3 weeks ago