How to display text above blog pages with Grav

October 09, 2019

For this website I wanted to run multiple small blogs alonglines and have category pages for "Gestaltung" and "Education". I wanted some decorative, introductory text above the blog posts rendered through

content:
    items: @self.children

I wanted something that now looks like this:

text

The way to display a blog in Grav is to use a unique power of grav. You create a page blog.md and define in its YAML section that this page should simply display links to all posts in folders that are children to this file's place.

content:
    items: @self.children

Adding this (and a blog.html.twig in your theme's templates folder) just creates a blog functionality. But how to get some intro-text above? My first guess was that adding text in the blog.md content section (below YAML) would display. But of course it doesn't.

Using modules

I am now using the modules functionality of Grav. I render a page, it's upper module is a text.md page and it's lower module is the blog.md page. This gives you the following structure for my Gestaltung-page:

folder structure

The modular.md carries this as its code:


---
title: Gestaltung
onpage_menu: true

content:
    items: '@self.modular'
    order:
        by: default
        dir: desc
---

It simply displays all modular pages within that folder (being, _blog and _descr) in descending order. That gives me the description text.md file on top. The text.md file within _descr is super simple.

The tricky part war getting the list of posts from blog.md to work. I am using the cacti for its multilanguage support. That has the blog functionality working with a post-list.md file that connects to a post-list.html.twig. Either works, in Grav its just words. They work the same. No matter how you name it, matters what carries the same name.