And maybe these methods can be of use for you: GitHub - hananils/kirby-date-methods: Kirby 3 plugin providing field and page methods for formatting dates and creating PHP date objects
Thank you so, so much, @nilshoerrmann !!! I implemented and adapted your collection code and my event blueprint and it got me to 90% of where I need it to be!
The cloning and displaying of recurring events worked flawlessly. I merged two collections for “recurring events” and “non-recurring events” into one collection that displays all future events into a calendar overview. This overview is basically just a foreach loop that feeds the collection items into an event snippet. The preview with all meta-data (title, date, category, …) is all displayed correctly.
My final end boss is this problem: The cloned events don’t link to the corresponding new subpages yet. They just lead to an error page.
My guess is that I need to add a routing function in the config.php file to link the new event slug with the subpages url somehow, but I couldn’t find this last puzzle piece in the docs so far.
Do you have any idea on how to solve this? Thanks again!
Just in case anyone else runs into a similar problem, I wanted to share how I ended up solving the last step. It probably isn’t the most elegant solution, but it works for what I tried to achieve. This is the routing setup in my config.php file:
'routes' => [
[
'pattern' => 'events/(:any)-(:num)',
'action' => function ($title, $startDate) {
// Check if the page exists in the original collection
$page = page("events/$title-$startDate");
// If not, check if it's in the recurrences
if (!$page) {
// Load the recurring events collection
$recurrences = collection('events-recurring');
// Iterate through each child in the recurrences collection
foreach ($recurrences as $recurrence) {
$recurrenceSlug = $recurrence->slug();
if ($recurrenceSlug === "$title-$startDate") {
// Create a new page using the 'event' template
$page = new Page([
'slug' => $recurrenceSlug,
'template' => 'event',
'content' => $recurrence->content()->toArray(),
]);
// Add the new page to the site structure
kirby()->site()->visit($page);
break;
}
}
}
// Check if the page exists after creating it
if ($page) {
return $page->render();
} else {
return site()->visit('error');
}
},
],
],
Thanks again, @nilshoerrmann! I probably would still try to doctor around with this if it wasn’t for your help