Add a created and updated date field blueprint and a hook that automatically updates the updated date when saving a page.

This commit is contained in:
2026-04-17 04:14:28 +10:00
parent e8c5e32768
commit aeaed44fcd
2 changed files with 28 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
type: fields
fields:
created:
label: Created
type: date
default: now
required: true
time:
notation: 12
step: 1
updated:
label: Updated
type: date
default: now
required: true
time:
notation: 12
step: 1

View File

@@ -24,6 +24,7 @@ Kirby::plugin(
"blueprints" => [ "blueprints" => [
"fields/link-locations" => __DIR__ . "/blueprints/fields/link-locations.yml", "fields/link-locations" => __DIR__ . "/blueprints/fields/link-locations.yml",
"fields/link-location" => __DIR__ . "/blueprints/fields/link-location.yml", "fields/link-location" => __DIR__ . "/blueprints/fields/link-location.yml",
"fields/dates" => __DIR__ . "/blueprints/fields/dates.yml",
], ],
"snippets" => [ "snippets" => [
"navbar/primary" => __DIR__ . "/snippets/navbar/primary.php", "navbar/primary" => __DIR__ . "/snippets/navbar/primary.php",
@@ -114,6 +115,14 @@ Kirby::plugin(
return $links; return $links;
}, },
"page.update:after" => function ($newPage, $oldPage) {
if ($newPage->updated()->exists()) {
# Set the last updated time to now.
$newPage->update([
"updated" => date("Y-m-d H:i"),
]);
}
},
], ],
"siteMethods" => [ "siteMethods" => [
/** /**