Hi folks,
I thought this would be a simple, but it appears not. What I would like to do is have the title and slug to be automatically generated when I create a “note” page within the panel.
In my ‘note’ blueprint I added the following:
create:
title: <?php echo date('Ymd-Hi'); ?>
slug: <?php echo date('Ymd-Hi'); ?>
But it seems that kirby won’t parse the php. So I tried doing it with a hook too, so I change the “create” options to something simple, like “note”:
create:
title: note
slug: note
Then have a hook to change the title/slug after the page is created:
'hooks' => [
'page.create:after' => function ($newPage) {
// Check if the created page is of the template 'note'
if ($newPage->intendedTemplate() === 'note') {
// Get the current date/time in the desired format
$dateTime = date('Ymd-Hi');
// Update the title and slug of the page to match the current date/time
$newPage->update([
'title' => $dateTime,
'slug' => $dateTime
]);
}
}
]
But this doesn’t work either. The title/slug just remain as “note”. Clearly I’m being an idiot, but I can’t work this seemingly simple thing out.
Thanks!