Filename keyword if statement

Hi -

I’m using the filter method to show only images that include ‘slide’ in the filename in a slider.

foreach($page->images()->filterBy('filename', '*=', 'slide')->sortBy('sort', 'asc') as $image): ?>
	          <li><img src="<?= $image->url() ?>" alt="<?= $page->title()->html() ?>" /></li>

Its working fine but I’m hoping someone out there can help me with an opening if statement to show the slider at all only if there are images present with the slide term in the filename.

As you can see I’m still learning the php side of things, but I’m trying! Thanks

You can use count() for this purpose:

$images = $page->images()->filterBy('filename', '*=', 'slide')->sortBy('sort', 'asc');
  <?php foreach($images as $image): ?>

    <li><img src="<?= $image->url() ?>" alt="<?= $page->title()->html() ?>" /></li>
  <?php endforeach ?>
<?php endif ?>

Wow, that’s perfect! Thank you so much!