I’m having issues excluding and including certain file names in a loop.
In the collection of files (images and videos) I have a poster image for each video. To match them i’m using the following filename structure:
video: myVideo.mp4, mySecondVideo.mp4 poster: myVideo.poster.gif, mySecondVideo.poster.gif [...the rest of images]
How would you exclude anything .poster from showing as image (
first if) and include a matching filename for video (
second if) - in case there are two or more videos with different names.
<?php foreach ($project->files() as $file): ?> <div> <?php if($file->type() == 'image'): ?> <img src="<?= $file->url() ?>"> <?php endif ?> <?php if($file->type() == 'video'): ?> <video poster="$video_file_name.poster.gif" > <source src="<?= $file->url() ?>" type="video/mp4" /> </video> <?php endif ?> </div> <?php endforeach ?>