Hide fields on blueprint depending on parent template

Hi,

I have a page with blueprint ‘Artwork’ that I used in two different places (Exhibition and Catalogue) within the site. I want to either set the a default pages field value on the child to its parent or remove that field if the Artwork was added from Catalogue page.

I have created a page model to populate a field, but at the moment I only got it working on an Info field which I can not use for conditions to hide the pages field on the child.

I saw there was proposal with a pr to add kql to the default of a field but it seems it didn’t got merged.

I don’t know if the “hidden” field would be an option here, I couldn’t find much information on the docs.

What are the possibilities to limit the visibility or default value of some fields based on the parent template?

Thank you

I have three thought trains that you my want to explore:

  1. Programmable blueprints (Programmable blueprints | Kirby CMS) where you could set the default via PHP depending on the parent. But it’s not a given, I am not sure if/how it is possible to retrieve the parent already during page creation (which is when the default would be written to the content file). So maybe not - even if it would be the most elegant one, if you could get it working. But could be hard.

  2. Use the page.create:before hook (Hooks | Kirby CMS) to check the new page’s parent and add the value depending on the parent.

  3. Don’t use the same blueprint, but actually make it two. The normal one and then use Reusing & extending blueprints | Kirby CMS to create the 2nd one without much repetition of code.

Thank you!

I had to change from page.create:before to page.create:after and it worked.

Here is the hook I am using:

'page.create:after' => function ($page) {
        if ($page->intendedTemplate() == 'artwork') {
          if ($page->parent()->intendedTemplate() == 'catalogue') {
            $page->update([
              'artist' => '- ' . $page->parent()->uuid()
            ]);
          }
        }
      }

I will try with the first option to see if I can get it working as well.