I’m merging structure fields (events) from different pages to show an overview of all events on a page, sorted by date. Each event has an image, which is saved outside the structure field, but in the page.
But now I can’t find a way to display the event with the corresponding image while looping through the new collection. How can I pass the image while the merging is happening, so I can keep the relation between both?
I’m using this as a plugin for the merging:
<?php
use Kirby\Cms\Structure;
function createNewStructure($pages, $field)
{
$structure = new Structure();
foreach ($pages as $p) {
$structure->add($p->$field()->toStructure());
}
return $structure;
}
And get the events like this:
<?php $pageCollection = $someCollection; ?>
<?php $mergedEvents = createNewStructure($pageCollection, 'events'); ?>
<?php foreach ($mergedEvents->sortBy('dateStart', 'asc') as $event): ?>
<?= $event->name() ?>
<?php $thumb = // How to get the image from the related page in $pageCollection? ?>
<img src="<?= $thumb->url() ?>">
<?php endforeach ?>
Thanks for any tip !