TWIG: Display/Access module from modular in a non-modular page

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

In your template include file

{% include 'partials/footer.html.twig' %}

or is there something special in your theme ?

Hey :wave:t3: 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.

Is it a block to be included on specific pages or all site ?

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

If I understand, the footer is not static but dynamique through the backoffice ?

Yes, exactly. Footer is editable module

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

:+1:

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)
grav-page-find

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.