How to render data from footer.md when it's included as a partial?

I’ve tried to look for information in the documentation, but couldn’t find anything on that.

I have a modular page and trying to add a footer as a partial, but currently no data from footer.md is being displayed.

I’ve added this code to the base.html.twig:
{% include 'partials/footer.html.twig' %}

This is working fine, but now, how do I render data from the footer.md file?

footer.md:

---
title: Footer
routable: false
icons:
    - icon: "facebook"
      link: "https://www.facebook.com/"
    - icon: "twitter"
      link: "https://twitter.com"
    - icon: "behance"
      link: "https://www.behance.net/"
    - icon: "linkedin"
      link: "https://be.linkedin.com/"
    - icon: "pinterest"
      link: "https://www.pinterest.com/"
copyright: "Project X 2015"
text: "Made with love for great people"
fonticon: "caret-up"
href: "#home"
---

footer.hml.twig:

<footer>
    <ul class="footer__sm__list">
        {% for item in page.header.icons%}
        <li>
            <a href="{{item.link}}">
                <i class="fa fa-{{item.icon}} fa-2x footer__sm__icon"></i>
            </a>
        </li>
        {% endfor %}
    </ul>
    <p>{{ page.header.copyright }}</p>
    <p>{{ page.header.text }}</p>
    <a href="{{page.header.href}}" class="footer__up"><i class="fa fa-{{page.header.fonticon}} fa-3x" aria-hidden="true"></i></a>
</footer>

Try something like this:

The code to include in base.html.twig must be:

{% include 'partials/footer.html.twig' with {'page': page.find('/footer', true)} %}

The footer.md file should be located in a folder called footer in user/pages

I tried it, it works

3 Likes

Here is one of my favorite ways:

{% set content = pages.find('/footer').content %}
{% if content %}
   {{ content }}
{% endif %}

This should work for Partials too…

3 Likes

Thanks a lot! I’ve used your method and it worked!

Used the other one and it worked fine, but will try out yours as well. Many thanks!

1 Like