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:
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.
Hi Sonja, do you have any idea how to solve this with Kirby v4?
I’m trying to show a “video cover” field in the Panel only when a video (mp4/webm) is uploaded in a files field that accepts both images and videos.
Is there any way to make a field appear based on the uploaded file type, without a plugin? Or is there a plugin that works with v4 (and ideally v5 in the future)?
No, that’s not possible out of the box. What’s the use case here? Why not add the cover in the files blueprint instead? Ans assign the correct file blueprint via a file.create:after hook?
Its essential to always have a video cover (poster) for HTML5 video tags, it acts as a fallback when the video doesnt autoplay, e.g. on iOS in low power mode or if loading fails. A generated screenshot on upload could be an option in the future, but from an art direction perspective, my clients need a carefully designed custom video cover.
Thats why id like the “video cover” upload field to appear only if the “mediafile” field contains a video. If a client selects just an image, having a extra cover field would only confuse them and will mislead people which are not briefed enough with panel use.
Do you think i can do another workaround with file.create:after hook ? Maybe im missing a function here whats possible.