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

How to get page title from footer when it’s included as a partial?

Started by LeMoussel 6 years ago · 1 replies · 937 views
6 years ago

I’ve tried to look for information in the documentation, but couldn’t find anything on that.
I have a blog page and trying to add a footer as a partial , but the title of the blog page from footer.md is not correctly displayed

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

pages/footer/default.md

YAML
---
title: Footer
routable: false
visible: false
process:
    markdown: true
    twig: true
twig_first: true
---
<h1>{{ page.title }}</h1>

partials/footer.hml.twig:

TWIG
<section id="footer" class="section bg-gray">
    <section class="container {{ grid_size }}">
      {% set footer_content = pages.find('/footer').content %}
      {% if footer_content %}
        {{ footer_content }}
      {% else %}
        <p><a href="http://getgrav.org">Grav</a> was <i class="fa fa-code"></i> with <i class="fa fa-heart-o pulse "></i> by <a href="https://trilby.media">Trilby Media</a>.</p>
      {% endif %}
    </section>
</section>

Whatever the title of blog pages I always have as a title in the footer the title of the page footer, i.e. Footer

is it possible to have the the title of blog pages ?

6 years ago

Hi. If I understand your question correctly, you would like the modular footer to display the title of the 'parent' page, rather than the title of the modular page?

If so, something like this should work:

TWIG
{{ page.parent().title }}

Suggested topics

Topic Participants Replies Views Activity
Content & Markdown · by Jochen, 10 months ago
6 925 10 months ago
Content & Markdown · by Ton Haarmans, 1 year ago
10 739 1 year ago
Content & Markdown · by Jan L'Am, 2 years ago
4 661 2 years ago
Content & Markdown · by Leonardo, 2 years ago
3 586 2 years ago
Content & Markdown · by belthasar, 2 years ago
4 959 2 years ago