Forum
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 (https://grabaperch.com/blog/archive/adding-markup-to-some-items-in-a-multiple-item-region). 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>
<div class=“row”>
</perch:every>
Does anyone have any thoughts about if this is possible? Thanks James
<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
It looks like you have the
perch:after
section inside a conditional - that won't work.perch:after
is essentially doing the same asperch_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.
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 withperch_content
.All good. Thanks everyone for your help.