Forum

Thread tagged as: Question

Counting Repeater Items

Hello,

I have a template that uses a simple repeater to add files for download to a region.

<h3><perch:content id="resSection" type="true" label="Resource Type"  /></h3>
<perch:repeater id="resourcelib" label="Resources" scope-parent="true">
    <a href="<perch:content id="resFile" type="file" label="File" bucket="class-documents" />">
        <perch:content id="resTitle" type="text" label="Title" title="true" />
    </a>
</perch:repeater>

I want to display only the 3 most recent resources and use a link to display all of the resources. Something like:

if(perch_get('r') == 'resources') {

   perch_content_custom('Resources', array(
        'template' => '_resources.html',
        'sort-order' => 'DESC'
   ));

} else {

   perch_content_custom('Resources', array(
        'template' => '_resources.html',
        'count' => 3,
        'sort-order' => 'DESC'
   )); 

}

Is there a way to count repeater items using perch_content_custom?

Thanks, Joshua

Joshua Rodriguez

Joshua Rodriguez 2 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You can do this in the template.

<perch:if id="perch_item_index" match="lte" value="3">
...
</perch:if>

Thanks Drew, exactly what I needed and it works perfectly.