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

Display dynamic page content on every page?

Started by Muut Archive 11 years ago · 3 replies · 283 views
11 years ago

I'm making a website for a local event (that happens monthly), and I want to have the date and location of the next event in the header and sidebar of every page. Having read the documentation, it doesn't seem possible to have more than one kind of content in a template. Is there a way to do this?

11 years ago

It sort of depends where you are going to store and therefor read this event information.

If you are storing this in the page header of a specific page, you could create a small twig template that simply finds this page, and then gets those header values. So something like:

Assuming a page like this in /user/pages/event-page/default.md:

YAML
title: Next Event
date: 10/23/15
location: Maui, HI

and then some custom twig template you can include on every page:

TWIG
{% event_page = page.find('/event-page') %}
<h2>Next Event</h2>
<p>Date: {{ event_page.header.date }}<p>
<p>Location: {{event_page.header.location }}</p>
11 years ago

Yep, this is pretty much what I was looking for, thanks! It's a little unintuitive (to me, anyway) to look for other page data using the current page. I was expecting something more along the lines of Grav.findPage('/event-page')

11 years ago

There are a variety of methods on the Page object. As this method relates to page types specifically, it makes sense to encapsulate that logic in the Page object itself. Really it's a personal preference of mine to keep like-functionality together :)

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1341 9 years ago
Archive · by Muut Archive, 9 years ago
2 928 9 years ago
Archive · by Muut Archive, 9 years ago
2 4057 9 years ago
Archive · by Muut Archive, 9 years ago
1 2942 9 years ago
Archive · by Muut Archive, 9 years ago
3 1115 9 years ago