joer80 Posted January 28, 2015 Posted January 28, 2015 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.) :\
joer80 Posted January 28, 2015 Author Posted January 28, 2015 Is it possible repeaters have a variable named description that is messing with the description field of an image in a repeater?
joer80 Posted January 28, 2015 Author Posted January 28, 2015 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 = ''; } }
joer80 Posted January 28, 2015 Author Posted January 28, 2015 The settings say max files = 0 (no limit), and formatted value is Automatic (single item or null when max files set to 1, array of items otherwise)
kongondo Posted January 29, 2015 Posted January 29, 2015 (edited) 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 January 29, 2015 by kongondo 3
joer80 Posted January 30, 2015 Author Posted January 30, 2015 I am pretty sure I tried to loop it again and it didn't work, but I will make sure! Thanks!
LedZepmann Posted February 26, 2015 Posted February 26, 2015 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>"; } } ?>
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now