Jump to content

Repeater not returning image description


joer80
 Share

Recommended Posts

Ok, I have a repeater on my page called Carousel, and it has an image field in it called Slider_Graphic.  

I am trying to access the image description field and I am not having any luck.  Can you tell me what I am doing wrong?

This is my code:

//Loop through Carousel repeater on this page

foreach($page->Carousel as $Slider){


  echo $Slider->Slider_Graphic->url;

  echo $Slider->Slider_Graphic->description;


}

It outputs this: /site/assets/files/29135/ for the url, but the description comes up empty.  (It is set in the backend.)

:\

Link to comment
Share on other sites

If I add a new text field called Caption to the repeater, it seems to work.  I just can't access the image description field.

this works:

foreach($page->Carousel as $Slider){
		
   if($Slider->Caption){ 
	  $Slidercaption = '<div class="carousel-caption"><h2>' . $Slider->Caption . '</h2></div>';
   } else {
	   $Slidercaption = '';
   }
   
   
}

Link to comment
Share on other sites

If max files = 0, then your images fields is an array and also needs to be looped or grab an image using $image->first() or $image->eq(2) if you only want a single image. Am surprised that the url was output though...hmmm.. Try the following...

//Loop through Carousel repeater on this page
foreach($page->Carousel as $Slider){//note that repeater items are just pages. So $Slider is a page 'with fields'

  //loop through the images array
  foreach($Slider->Slider_Graphic as $graphic) {//foreach image field in each $Slider page...

    echo $graphic->url;
    echo $graphic->description;

  }
 
}
Edited by kongondo
  • Like 3
Link to comment
Share on other sites

  • 4 weeks later...

If max files = 0, then your images fields is an array and also needs to be looped or grab an image using $image->first() or $image->eq(2) if you only want a single image. Am surprised that the url was output though...hmmm.. Try the following...

//Loop through Carousel repeater on this page
foreach($page->Carousel as $Slider){//note that repeater items are just pages. So $Slider is a page 'with fields'

  //loop through the images array
  foreach($Slider->Slider_Graphic as $graphic) {//foreach image field in each $Slider page...

    echo $graphic->url;
    echo $graphic->description;

  }
 
}

I was experiencing this same problem and the second loop did the trick!

<?php 

  foreach ($page->slider as $slide) {

    foreach ($slide->slideimage as $image) {

       echo  "<a href='{$slide->slidelink}'><img class='radius' width='1000' src='{$image->url}' alt='{$image->description}'></a>";

  }
}
?>
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

  • Recently Browsing   0 members

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