Forum
Repeaters with if exists
I'm using a repeater for a product page images. I then want to have one of the images used on a listing page which can be chosen in Perch. I'm using a checkbox type for this.
Product details template
<perch:repeater id="productimg" label="Product Images" max="4">
<div class="slide">
<img src="<perch:content id="productimg" type="image" label="Image" bucket="Products" width="432" height="432" crop="true" />
<perch:content id="productimg" type="image" label="Image" bucket="Products" width="70" height="70" crop="true" suppress="true" />">
<perch:content id="listing_img" type="checkbox" label="Use on Listing Page?" value="1" suppress="true" />
</div>
</perch:repeater>
Product listing template:
<perch:repeater id="productimg" label="Product Images" max="1">
<perch:content id="listing_img" type="checkbox" label="Use on Listing Page?" value="1" />
<perch:if exists="listing_img">
<img src="<perch:content id="productimg" type="image" />">
</perch:if>
</perch:repeater>
No image is appearing, is this something to do with being inside a repeater as I've tested the condition elsewhere and it achieves the desired results.
If both the checkbox and the image are within the repeater (as it looks to me) then that should be no problem - both are in scope.
Does
<perch:showall />
show the value of the checkbox?It's returning "1" for the listing_img array for the productimg field but nothing inside the listing_img
Is this 2.8.11?
Yes it is 2.8.11
I've figured out the issue, I was using max="1" on the listing pages as I don't want more than one listing image appearing, but I guess that only makes the first image available.
Is there a way to limit the output to 1 image another way incase the client ticks more than one by accident?
You could test for
perch_item_first
.