Subpage builder doesn't call hook?

Hello there,

I got the problem, that the panels subpage builder is not calling the hook if it creates new subpages.

I created the following subpage builder:

    - title: Infobox
      uid: event_info
      num: 1
      template: module.cardinfo_subpage

If the page creates the subpage my hook is not called. If I delete that created sub page and recreate it by hand, then the hook is called and works perfectly.

This is my hook:


    kirby()->hook([''], function($page) {
      if($page->uid() == 'event-info') {
        $today = date('l, d.m.y' , time());

        $page->update(array('datepicker' => $today), 'yml');

I want to use that hook to set the current date as default value. This is really important because I want to make sure that the field can never be empty, even if it does not get filled in. Using default values via the blueprint is not the right way for my problem :confused:

Is it normal that hooks are not getting fired up when using the subpage builder?


No, that shouldn’t be happening. I have marked this for 2.4.

Okay thanks for confirming.

Is there any workaround of how I can populate a field when a page is being created?

Well, if you want to make absolutely sure that the field cannot ever be empty, you should provide the fallback directly in the controller/template. You can use the file creation date for that.

you mean that in my template I do something like this:?

  // $event_info is a page object
        $today = date('l, d.m.y' , time());
        $event_info->update(array('datepicker' => $today), 'yml');

you could also use modified property of page object as fallback in your template instead of current time.

I wouldn’t save the value to the text file in those cases, but that depends on your use-case of course.