md81
October 31, 2020, 12:05am
1
Dear community,
in Twig , how is it possible to display a module (footer) from a modular page (home) inside of all parent pages (e. g. legal)
pages
01.home (modular)
— 01._hero
— 02._main
— 03._footer -> this one …
02.legal -> … should also be visible here
Thanks a lot!
Marcus
Kit
October 31, 2020, 1:57pm
2
In your template include file
{% include 'partials/footer.html.twig' %}
or is there something special in your theme ?
md81
October 31, 2020, 2:13pm
3
Hey First of all, thank you. Simply including the file would include also the
{{ page.content }}
… defined in footer twig, but grabbing the page content of the current page (02.legal)
That’s my problem.
Kit
October 31, 2020, 2:55pm
4
Is it a block to be included on specific pages or all site ?
md81
October 31, 2020, 3:20pm
5
Sorry, my fault. I wasn’t detailed enough.
The Module Footer (which is part of modular Home) should be visible all site.
Pages structure:
01.home (modular)
— 01._hero
— 02._main
— 03._footer -> this one …
02.legal -> … should also be visible here
03.another page -> … should also be visible here
04. … -> … should also be visible here
Footer Module (footer.html.twig):
<footer id="{{ page.menu|hyphenize }}" class="footer theme-dark">
<article class="grid">
{{ page.content|markdown }}
{% include 'partials/langswitcher.html.twig' %}
</article>
</footer>
default.html.twig:
{% extends 'partials/legal.html.twig' %}
{% block page_content %}
<main>
{{ page.content }}
</main>
{% include 'modular/footer.html.twig' %}
{% endblock %}
Kit
October 31, 2020, 5:38pm
6
If I understand, the footer is not static but dynamique through the backoffice ?
md81
October 31, 2020, 7:47pm
7
Yes, exactly. Footer is editable module
md81
November 1, 2020, 12:10am
8
Ok, I got it. Funny that it took me quite a lot of time to find out, that the solution already has been documented in the cookbook!:
In my Case the solution was:
{% extends 'partials/legal.html.twig' %}
{% block page_content %}
<main>
{{ page.content }}
</main>
{% include 'modular/modular_reuse.html.twig' with {'page': page.find('/home/_footer')} %}
{% endblock %}
Thanks a lot @Kit
Kit
November 1, 2020, 8:15am
9
there is also this method
{% if page.find('/modules/sidebar').content %}
{{ page.find('/modules/sidebar').content|raw }}
{% endif %}
In backoffice add “Folder” and add page with same name (exemple : sidebar)
phi
November 1, 2020, 1:03pm
10
Since the legal info will occur on all pages, I would consider moving the content to a global config file like user/config/legal.yaml
and populate the template from this. You could also make a corresponding blueprint to edit the content in the admin.
With the legal content in a module of the home page, It would not be obvious where that content would be found without instructions.