Automatic date created/modified in panel

I’m discovering Kirby and liking what I see but there are a few things I haven’t grasped yet.
For example, I’d like to store on each page created with the panel a field with the date (in dd:mm/yy hh:ss format) it is and, in another field, the date it is modified (if ever and if not, date modified = date created).

Something like this :

dcreated:  13/12/2016 08:07
dmodified: 13/12/2016 10:10

What I don’t get is where to put the code to that effect, in the blueprint, elsewhere ?
And how, using straight PHP or is there something provided by Kirby that I haven’t discovered yet ?

Hope that’s not too dumb a question --and that it hasen’t been answered too many times already (I checked), thanks in advance for any help.

The fields you need are defined in the blueprint for that page. As regards the time of creation, you can set a default date/time (default: now), so that the date the page is created gets saved.

For the modified date, the question is if you need a field. You can get the information directly via the $page->modified() method in your templates:

If you nevertheless want to store that information in the text file itself, you can use a hook that stores the date/time on page update:

OK, thanks, I’ll be looking into hooks a bit later and using $page->modified() for now.

If you run into issues with setting up a hook, don’t hesitate to ask, we are (almost always) here to help :slight_smile:

OK, I have a follow-up : if I wanted the “dcreated” field to be visible but non-modifiable by the user, how would I declare it ?

You can set it to readonly: true

Never mind, I think hooks are again the answer in this case.

You’d still want to make the creation date readonly, with or without hooks, because the page creation hook is only triggered once.