Conditional field in File Blueprint based on file type

Hi,

I try to make a field only visible in a File Blueprint if the file is an image. Any suggestions, how can I achieve this? (Restricting the file upload to images only is not an option, other files are allowed as well.)

The $file->type() == "image" ($file->type() | Kirby CMS) condition works well to distinguish images from other files, but I can’t figure out how to add it to a when field condition. (Fields | Kirby CMS)

This does not work:

when:
  type: image

I tried creating a field method in a plugin (File methods | Kirby CMS) to create a binary method and use it as part of the condition, but this didn’t work either:

when:
  isImage: true

Thanks!

The when query only works based on actual field values, you cannot match it against backend stuff like file methods.

What you could do, it is use the Whenquery plugin, it has access to the mime type of the file: GitHub - rasteiner/k3-whenquery: Conditionally show fields and sections. Better.

1 Like

I’m browsing around looking for a way to use videos in the same image file blueprint using the when as well.
Might as well make a video file blueprint, I suppose.