Jump to content

[SOLVED] Get all images in a Repeater


muco
 Share

Recommended Posts

Hi guys,

I created an image field (studio) which can contain up to 30 images. Then I created a repeater field (studioimages) and added the studio field.

I added some images to the repeater:

images.thumb.png.516ceac24134c777a55fff90688c70ba.png

Now I loop through the repeater, but I only got the first image or no image:

foreach($page->studioImages as $studioImage) {
  echo "<div class='swiper-slide'>
    <div class='image-gallery'>
      <a href='{$studioImage->studio->url}'>
        <div style='background-image: url({$studioImage->studio->url});'>

        </div>
      </a>
    </div>
  </div>";
}

I also tried "$studioImage->studio->first()->url" and "$studioImage->studio" but nothing works. Can you tell me what is wrong?

Link to comment
Share on other sites

Each repeater item is a page itself, and repeater field is the parent page that holds these. (You can even see it under Admin>Repeaters).

You need to iterate over $page->studioImages to get each set, than iterate over them to get individual images. Here's how:

<?php foreach ($page->studioImages as $imgSet): // each repeater item ?>
    <div class="swiper-slide">
        <div class="image-gallery">
            <?php foreach ($imgSet->studio as $img): // each image in a repeater item ?>
                <a href="<?= $img->url ?>">
                    <div style="background-image: url(<?= $img->url ?>)"></div>
                </a>
            <?php endforeach; ?>
        </div>
    </div>
<?php endforeach; ?>

 

  • Like 7
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...