It seems that I’m almost there but need the last bit to get it all working…
Instead of creating a lot of templates for similar pages I want to have a simple conditional which checks the uuid of the current page. Based on that condition I show a section, like an overview of productions, or the playdates of said productions.
This is what I have now, which unfortunately doesn’t work. If someone can steer me in the right direction it would be awesome
<?php // first we check if we're on the calendar page
if ($page->uuid() === 'page://sPZAnprGa36jrSYv'): ?>
<h2><?= t('playdates') ?></h2>
<ul>
<?php
// we then target the productions which all are children of the productions page
$productions = $site->find('page://YDLYvueOhZwB3glM')->children()->listed();
// we loop through each of them to reach their data
foreach ($productions as $production):
// using the `toStructure()` method, we create a structure collection
$items = $production->playdates()->toStructure();
// we loop through the entries and render the individual fields
foreach ($items as $item): ?>
<li>
<?= $item->playdate()->toDate('EEEE d MMMM Y – H:mm') ?>
<?= $production->title() ?>
<?= $item->location() ?>
<?= $item->city() ?>
<?php if ($item->ticketlink()->isNotEmpty()): ?>
<a href="<?= $item->ticketlink() ?>">tickets</a>
<?php endif ?>
</li>
<?php endforeach ?>
<?php endforeach ?>
</ul>
<?php endif ?>
The first conditional if ($page->uuid() === 'page://sPZAnprGa36jrSYv')
doesn’t work. Without this conditional the list is rendered, but on all pages. I like to only show it when we’re on the calendar page.