Conditional fields with conditions in OR - a workaround

Hi, I know that conditional fields with more than one condition works by design in “AND”. And I also know there’s a plugin to extend the behaviour.

But I wonder if it could be ok to duplicate the field to match the specific condition. My case is:

  • I have 3 “post_type”(s): “post”, “newmusic”, “news”

  • “abstract” field should be visibile only it post_type = “post” and post_type = “newmusic”

  • so I created a blueprint like this

            abstract: 
              label: Abstract
              type: blocks
              default:
                - type: text
              when:
                post_type: post
            abstract: 
              label: Abstract
              type: blocks
              default:
                - type: text
              when:
                post_type: newmusic
    

…but it doesn’t work, as when the post type is “post” the fields remains hidden. Any other suggestion? Thanks.

Fields with the same name are not possible, why don’t you want to use the plugin?

well… i’m trying to avoid using plugins as I’ve run into incompatibility issues in the past. Kirby goes forward… sometimes plugins won’t follow. Moreover I couldn’t find GitHub - rasteiner/k3-whenquery: Conditionally show fields and sections. Better. among the K4 plugins listen on the official site.

That can indeed happen.

If you absolutely don’t want to use the plugin, use two different field names, e.g. abstract_post and abstract_newmusic. Then you can call these fields conditionally in your template, depending on post type.

Example code:

<?php if (in_array($page->postType(), ['post', 'newmusic']) && $page->{'abstract_' . $page->postType()}()->isNotEmpty()): ?>
<div><?= $page->{'abstract_' . $page->postType()}() ?></div>
<?php endif ?>