Hello,
I have images
, videos
, audio
files as well as documents
. Each file type has its own blueprint and sortable upload area. In my page template, each file type has its own area: images
appear first, followed by videos
and audio
files. This works well.
Now, I want to enable the user to mix and sort different file types, for example, he can put a video in the first place, a picture in the second and a video again in the third by using the panel. I am facing several problems here:
Images
,videos
andaudio
files should appear here only.Images
,videos
andaudio
files need different HTML tags such asimg
,video
andaudio
.
So far, I created one upload area for specific suffixes in my page blueprint:
media:
type: files
template: media
as well as a file blueprint:
title: Media
accept:
extension: jpg, png, gif, mp4, mp3
fields:
alt:
label: Alt
type: text
caption:
type: text
My page template outputs all files roughly at the moment:
<?php if ($page->files()->isNotEmpty()): ?>
<?php foreach ($page->files() as $file): ?>
<figure>
<?= $file ?>
<?php if ($file->caption()->isNotEmpty()): ?>
<figcaption>
<?= $file->caption()->kirbytext() ?>
</figcaption>
<?php endif ?>
</figure>
<?php endforeach ?>
<?php endif ?>
but I aim to output files type-specifically:
<?php if ($page->images()->isNotEmpty()): ?>
<?php foreach ($page->images() as $image): ?>
<figure>
<?= $image->resize(1200, 1200, 90) ?>
<?php if ($image->caption()->isNotEmpty()): ?>
<figcaption>
<?= $image->caption()->kirbytext() ?>
</figcaption>
<?php endif ?>
</figure>
<?php endforeach ?>
<?php endif ?>
<?php if ($page->videos()->isNotEmpty()): ?>
<?php foreach ($page->videos() as $video): ?>
<figure>
<video autoplay controls loop>
<source src="<?= $video->url() ?>" type="video/mp4">
</video>
<?php if ($video->caption()->isNotEmpty()): ?>
<figcaption>
<?= $video->caption()->kirbytext() ?>
</figcaption>
<?php endif ?>
</figure>
<?php endforeach ?>
<?php endif ?>
<?php if ($page->audio()->isNotEmpty()): ?>
<?php foreach ($page->audio() as $audio): ?>
<figure>
<audio autoplay controls loop>
<source src="<?= $audio->url() ?>" type="audio/mpeg">
</audio>
<?php if ($audio->caption()->isNotEmpty()): ?>
<figcaption>
<?= $audio->caption()->kirbytext() ?>
</figcaption>
<?php endif ?>
</figure>
<?php endforeach ?>
<?php endif ?>
How do I determine and appropriately output different file types in my template now? All files should be displayed as sorted in the panel and with the correct HTML tag.