Jump to content

Recommended Posts

Posted

I've set up a repeater field and it is working properly except that I don't know the proper syntax to get the images in the repeater field displayed.

Here's what I've got so far:

<? foreach($page->home_bullets as $bullet): ?>
 
    <div class="col group">
       <div class="col first"><img src='{$image->url}' alt='{$image->description}'></div>
       <div class="col second"><span><?=$bullet->body ?></span></div>
    </div>
 
<? endforeach; ?>
 
I assume that somewhere I have to define what $images actually is (i.e. $home_bullets->images as $image) or something of the sort, but I have no idea where to do it.
 
The repeater field only has two fields in it, images and body.
 
Any help is greatly appreciated!
Posted

Hi, 

This might be helpful to you.

<?php foreach($page->home_bullets as $bullet): ?>
 
    <div class="col group">
       <?php 
       // get the very first image from images list since image field is accepting multiple images (unless you change the value of `Maximum files allowed` under Fields > images > Details tab > Maximum files allowed).      
       $image = $bullet->images->first(); 

       ?>
       <div class="col first"><img src="<?php echo $image->url; ?>" alt="<?php echo $image->description; ?>"></div>
       <div class="col second"><span><?=$bullet->body ?></span></div>
    </div>
 
<?php endforeach; ?>

Thanks

Posted

The thing you should remember is that each item in the repeater is a Page. You should threat them as they are pages.

foreach ($page->home_bullets as $bullet) <-- here bullet is the page

If images is a multi image field, you can get them all with the repeater-item page.

$bullet->images // all images, these can be looped. (see the page named $bullet, coming from the foreach above )
  • Like 1

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...