Forum

Thread tagged as: Question, Problem

content_custom: pulling first image from repeater

I would like to just pull the first image from the array of images found in a repeater. I thought that using perch_content_custom may allow this to happen with the "count" option, but I appear to get all the images in the array.

This is the call using a custom template:

<?php
    perch_content_custom('Showhome', array(
        'template'  => '_showhome_thumb.html',
        'count' => 1
    ));
?>

and the template looks like this:

<perch:repeater id="images">
    <perch:if exists="image">
        <img src="<perch:content id="image" bucket="showhome" />" alt="Showhome" />
    <perch:else />
        <img src="/img/photo-showhome-small.jpg" alt="showhome" />
    </perch:if>
</perch:repeater>

I am using Perch 2.5.4.

I must be missing something, can anyone shed some light on this for me?

James Harrison

James Harrison 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

The count is for the items, not the repeater.

You could add a test for perch_item_first in the repeater

<perch:if exists="perch_item_first"> ... image ... </perch:if>

That's great Drew - thanks for letting me know about that! That works great, but it triggers the content of the else statement when I use it. Removing the else statement solves the problem, but also gets rid of the fallback.

Drew McLellan

Drew McLellan 2638 points
Perch Support

What does your template look like?