Looping images from specific page

Hi all - Aware this is a stupidly simple question, but am after a way to loop images from a specific page. I’ve certainly done it before but brain has gone to mush and was hoping someone could help.

In the example below the template ‘accreditations’ is the page i’m targeting, and i just want to show the images from that page. The code below doesn’t work though.

<?php foreach($page('accreditations')->images() as $image): ?>
      <a href="<?= $image->url() ?>">
        <img src="<?= $image->url() ?>" alt="">
      </a>
    <?php endforeach ?>

should be page('accreditations'), but you should use an if statement to check if the page exists.

Argh thanks so much, I missed that! That’s a foggy brain for you. In this instance what’s the best way to do an if statement to check page exists?

<?php 
$p = page('accreditations');
if ($p) :
foreach($p->images() as $image): ?>
      <a href="<?= $image->url() ?>">
        <img src="<?= $image->url() ?>" alt="">
      </a>
    <?php endforeach ?>
<?php endif; ?>

Gotcha, thanks so much. Always learning :smiley: