i don’t seem to be able to get kirby to assign an automatic date when i upload a file. everytime i open the individual file page in the panel, the date field is empty. it works neither with a specific date or “today”
here is what i have in my file blueprint
sidebar:
width: 1/3
fields:
date:
label: created
type: date
default: 2020-05-01
more:
type: link
That field is to manually enter a date. You need to use a hook to set the field automatically when you upload or replace the file.
Full list of hooks here:
Use update() inside the hook to update the files content text file.
Alternatively you could do away with the field and just read the files modified date directly from the the file in template.
okay, i seem to be getting somewhere with this. here is what i wrote now:
'hooks' => [
'file.create:after' => function (Kirby\Cms\File $file) {
$newFile = $file -> update( [
'date' => date('Y/m/d')
]);
$file = $newFile;
echo 'creation date set to today';
}
],
when i try to upload a file, it says that “The file could not be uploaded”, but on page refresh the file does appear, and the date is set correctly. so i assume i did something wrong, but not wrong enough.