Jump to content

stuck with repeater


Marco Angeli
 Share

Recommended Posts

Hi everybody,

I'm trying to use a repeater field to list different articles with a title, a description and an image gallery. This is what I want to achieve:

<article class="ed2">                

<h3>title</h3>

<p>

very long description

</p>

<ol class="thumb-grid group">
    <li><a href="#"><img src="assets/temp-img.png" alt="thumbnail" /></a></li>
    <li><a href="#"><img src="assets/temp-img.png" alt="thumbnail" /></a></li>
    <li><a href="#"><img src="assets/temp-img.png" alt="thumbnail" /></a></li>
    <li><a href="#"><img src="assets/temp-img.png" alt="thumbnail" /></a></li>
</ol>        


</article>    

 

I'm using this code (just testing if images are ready to use):

<?php

    foreach($page->evento as $event){

        echo "<article class='ed2'>";
        
        echo "<h3>{$event->titolo_evento}</h3>";
        
        echo "{$event->descrizione_evento}";
        
        echo "<ol class='thumb-grid group'>";

        echo "{$event->img_evento}";
        
        echo "</ol>";
                
        echo "</article>";

    }


?>
 

my output is this:

<ol class='thumb-grid group'>020.jpg|175-0.jpg|ox.jpg</ol>
 

So I Know all the images I uploaded are in place, but how do I loop inside the "img_evento" field to echo different urls?


 



 

Link to comment
Share on other sites

Hi Marco,

Your field 'img_evento' holds multiple images. To output them, you need another loop:

if (count($event->img_evento)) {
  echo '<ol class="thumb-grid group">';
  foreach ($event->img_evento as $image) {
    echo '<li><a href="#"><img src="'.$image->url.'" alt="'.$image->description.'" /></a></li>';
  }
echo '</ol>';        

You can also create thumbnails inside the loop if your images need to be smaller.

  • Like 2
Link to comment
Share on other sites

Hey Wanze!

With your suggestion I get some good result.. here's my code:

<?php

    foreach($page->evento as $event){

        echo "<article class='ed2'>";
        
        echo "<h3>{$event->titolo_evento}</h3>";
        
        echo "{$event->descrizione_evento}";

        
        if (count($event->img_evento)) {

          echo "<ol class='thumb-grid group'>";

                foreach ($event->img_evento as $image) {
                echo "<li><img src='$image->url'></li>";
                }
            
           echo "</ol>";
            
          }
          

                
        echo "</article>";

    }


?>
 

As you said, I need thumbnails but this doesn't work:

        if (count($event->img_evento)) {

          echo "<ol class='thumb-grid group'>";

                foreach ($event->img_evento as $image) {
                echo "<li><img src='$image->size(100, 100)->url'></li>";
                }
            
           echo "</ol>";
            
          }
 

...
 

Link to comment
Share on other sites

but this works:

        if (count($event->img_evento)) {

          echo "<ol class='thumb-grid group'>";

                foreach ($event->img_evento as $image) {
                
                //referring to your field_name > input > thumbnail setting
                $thumb = $image->getThumb('thumbnail');
                
                echo "<li><a href='{$image->url}' class='fancybox' rel='gallery' title='{$image->description}'><img src='{$thumb}' alt='{$image->description}'></a></li>";
                }
            
           echo "</ol>";
            
          }
 

...thanks to 97's: http://processwire.com/talk/topic/643-release-thumbnails/page-6


 

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...