Recognize image or video in a template

Without the else doesn’t show the video, but the video.jpg.
Anyway, I put a VideoUrl: field with url to the Vimeo video and then this in the projects code:

  <?php if($images = $page->images()->filterBy('filename', '!=', 'video.jpg')): ?>
     
    <a href="<?php echo $page->VideoUrl() ?>">Video</a>

  <?php else: ?>
    <?php foreach($page->images()->sortBy('sort', 'asc') as $image): ?>
      <img src="<?php echo $image->url() ?>" 
      data-caption="<?php echo html($image->caption()) ?> <?php echo html($image->photographer()) ?>" 
      data-full="<?php echo $site->url() . '/content/' . $page->diruri(). "/full/" . $image->filename(); ?>" >
    <?php endforeach ?>

  <?php endif ?>

In this case I’m using fotorama to manage the video :slight_smile:

1 Like