Thread tagged as: Question, Api, Docs

Determining Repeater Last Item

Hi I am hoping someone can help me with a simple question. I am new to Perch and have been following this example for repeaters and creating rows of images ( What I have noticed is that if the number of items is 3, or 6 or 9 etc, then the example in the blog will add an empty div / row after the row of images. So, essentially to prevent this, I think we need to test if the count=3 item is the last item. Pseudo code might look something like the following...

<perch:every count="3" and not last item>
   <div class=“row”>

Does anyone have any thoughts about if this is possible? Thanks James

James Heanly

James Heanly 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

<perch:if exists="perch_item_last"> ... </perch:if>

Hi Drew, Thanks for your help. I have tried your suggestion and it doesn't seem to be working. Am I doing something wrong - code is below

<perch:repeater id="products" label="Product" max="6">
        <div class="row">
    <div class="col-sm-4">
        <div class="team-bio">
                <img src="<perch:content id="product_image" type="image" label="Product Image" />" />
            <div class="team-description">
                <div class="member-name">Another Product</div>
                <div>A Description</div>
        </div><!--/team bio-->
    </div><!-- col-sm-4 -->

    <perch:if exists="perch_item_last">
        <!-- DO NOTHING -->
    <perch:else />
        <perch:every count="3">
            <div class="row">
Drew McLellan

Drew McLellan 2638 points
Perch Support

It looks like you have the perch:after section inside a conditional - that won't work. perch:after is essentially doing the same as perch_item_last but it's processed out of context.

Hi Drew I have worked out the problem. It seems like some sort of caching is being performed on the template. So, what I had to do was make the code change to the template, and then go back into the Perch Manage Content dashboard and Save the Region to which the template belonged. Does that sound correct to you, or is there another way to make sure a code change to the template becomes active without have to edit the region in the Perch dashboard? Thanks James

James, You are correct... perch_content() regions are cached so any template changes will not affect the region without re-saving or "republishing"

perch_content() is cached

perch_content_custom() is populated at runtime, meaning template changes are immediate without resaving the region.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Yes when you use perch_content we cache this to help keep things fast, so unless you need to do something dynamic we'd suggest sticking with perch_content.

All good. Thanks everyone for your help.