Same blueprint, different defaults or visibility

Hi,
I’d like to use the same blueprint for different kinds of articles - let’s say “Projects” and “Posts”.

90% of the fields are the same; I would like to handle the remaining 10% setting a different default value (they’re Select fields) according to the parent page UID (‘project’ or ‘post’).

In alternative, it’s ok to have different fields, but I wasn’t able to make the WHEN property works with a query statement:

          date:
            label: Data
            type: date
            default: today
            width: 1/4
            when: page.parent.uid = "posts"

This would make the site’s editors work a little bit easier.

Is it possible?

thank you
Francesco

You can reuse and extend blueprints, maybe that’s a better approach?

Default when only works with values from other fields on the same page. The Whenquery plugin gives you more options (GitHub - rasteiner/k3-whenquery: Conditionally show fields and sections. Better.), but you still cannot query other pages props, so won’t help for the example.

Another option are PHP blueprints:

…what about page.create:after hook?

You mean to set default values if no value is provided? That’s an option, although I’d personally prefer a page model that overwrites the writeContent method for this use case.

Won’t help with hiding/showing fields in your blueprint, though.

In the end, I’ll go with the page.create:after hook. So I can set a custom post_type field, and then using the WHEN property on the other fields that have to be hidden.

I’ve had some troubles though, because I guess the bnomei/autoid plugin use the same hook. I’ve disabled the plugin and everything went fine (sorry @bnomei, your plugin works like a charm in all the other cases).

1 Like

Unique ideas for pages, files and users are built-in since Kirby 3.8.0.

1 Like