Display field when file is video

Hey there,

I’m building a website with images and videos.

For the videos, I would need a file field in order to upload the poster.

So in my default file blueprint, Is there a way to have a file field when the file is a video ? Something like:

when:
     filetype: video

Otherwise, Can I have two blueprints image.yml and video.yml that are automatically selected from the file type?

Thanks a lot!

Conditions only work based on the content of another field. However, you could employ a little workaround:

On file upload store the file type in a hidden field using a file.create:after hook.

1 Like

Thanks! I’ll take a loot at that! :slight_smile:

Hey,

Another question,

After setting my blueprint and upload the cover, I have set the poster in my video tag:

poster='<?php echo $file->cover()->url()?>

yet it doesn’t work because it returns the url with a dash before:

<video muted="" loop="" playsinline="" preload="none" poster="- albums/video-test/cover-1.png" src="http://localhost/test/media/pages/albums/video-test/xxxx.mp4"></video>

Am I missing something here?

That’s because you have to try and convert your field content to a file object first, then check if you have a file object before you call the url() method.

Code:

poster="<?php echo ( $poster = $file->cover()->toFile() ) ? $poster->url() : ''; ?>"

Thanks!
Do you have any link to the guide where this is explained? I must have missed it!

(Almost) every field has a section how to use it in your templates/snippets:

Oh yes actually I knew that since I’ve used it overall my websites :sweat_smile:

Misunderstanding on my side! Thanks a lot :slight_smile:

What you can do is to set the filetype on upload like this:

'file.create:before' => function (Kirby\Cms\File $file) {
	return $file->update(['filetype' => $file->type()]);
},