Adding a class to last file

Hi,

I’m trying to add a class the the last image of a slider. Am I doing something wrong here? My code is not working :frowning:

<?php foreach($page->slider()->toFiles() as $mediaFile): ?>

  <?php

    // Classes

    $class = 'space-bottom-3x';

    if ($mediaFile->isLast()) {
      $class = $class . ' space-bottom-none';
    }

  ?>
  <img class="<?php echo $class; ?>" ...>
<?php endforeach ?>

Best,
Johan

Could you try something like that?


$files = $page->slider()->toFiles();

foreach($files as $file) {
  if ($file->isLast($files)) {
      // todo
  }
}
2 Likes

Awesome, that did the trick!