I’ve updated a website from Kirby 2 to 3. On a page template I use a date field that automatically alters the title of the page in the date.
In Kirby 2 I used a plugin for that, but in Kirby 3 this is not working. So I wrote it als a hook in the config file. But somehow I don’t get this to work.
What am I doing wrong? Or beter, is there another way in Kirby 3 to accomplish the goal (have a date field als title.
'page.update:after' => function ($page) {
if ($page->intendedTemplate() === 'event') {
$title = $page->date()->toDate('Ymd');
$uri = str::slug($title);
// Stop if there's a sibling with same date
if (! $page->parent()->find($uri)) {
// otherwise update title and URI
$page->update(compact('title'));
$page->move($uri);
}
}
}
Oh, ok, but that means that the URLs to these pages will keep changing as well whenever a user changes the date? Just wondering if that is a good idea… What is your use case? And why does the date have to be in the title/slug at all? What happens if there are multiple events with the same date?
But as I wrote above, when you change the slug in a hook, you will not be redirected to the new location and your users will see an error.
True. That might not be a good idea, as you explained.
The reason that I set it up like this, is that the page order is always by date. It’s an event calendar. So it’s logical to have a chronicle order of te events in the panel and content folder. But maybe this can be achieved in a different way.