Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Content & Markdown

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

Started by Oona O'Neil 9 years ago · 4 replies · 1321 views
9 years ago

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:*

YAML
---
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:

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>
9 years ago

Try something like this:

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

TWIG
{% 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
9 years ago

Here is one of my favorite ways:

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

This should work for Partials too...

👍 3
9 years ago

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

👍 1

Suggested topics

Topic Participants Replies Views Activity
Content & Markdown · by Jochen, 8 months ago
6 94 8 months ago
Content & Markdown · by Ton Haarmans, 1 year ago
10 184 1 year ago
Content & Markdown · by Jan L'Am, 1 year ago
4 146 1 year ago
Content & Markdown · by Leonardo, 1 year ago
3 60 1 year ago
Content & Markdown · by belthasar, 1 year ago
4 254 1 year ago