Forum

Thread tagged as: Shop

scope-parent="true" not working for slug field inside if statement inside reapea...

Hi. I am trying to return just the first item in a repeater region to the template...

to do that, I'm using

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

But when I do that, the first item that uses scope-parent="true" to return the slug value returns nothing. The title field is returned.

<perch:repeater id="repeater_images" label="Additional Images">
<perch:if exists="perch_item_first">
<a href="/product.php?product=<perch:shop id="slug" type="slug" scope-parent="true" />"><img src="<perch:shop id="image_secondary" type="image" width="800" height="800" density="1.6" crop="true" />" alt="<perch:shop id="title" scope-parent="true"/>"></a>
</perch:if>
</perch:repeater>
Monty Lewis

Monty Lewis 2 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

scope-parent="true" goes on the perch:repeater tag.

oh wow! I've always used it on the field in the repeater!

Moving the tag to the repeater does not change it though. Still works on the title field, but not on the slug field within an if statement...

Thanks, Monty

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show me your corrected code?

sure.

<perch:repeater id="repeater_images" label="Additional Images" scope-parent="true">
    <perch:if exists="perch_item_first">
               <a href="/product.php?product=<perch:shop id="slug" type="slug" />"><img src="<perch:shop id="image_secondary" type="image" width="800" height="800" density="1.6" crop="true" />" alt="<perch:shop id="title" />"></a>
        </perch:if>
</perch:repeater>

it's used on this page to add the 2nd image to each listing if that helps:

https://stopherethisistheplace.com/shop

-- Monty

Drew McLellan

Drew McLellan 2638 points
Perch Support

Inside the repeater, you need to use parent.slug to address the field from the parent scope.

Thank you!

Hi Drew so the "inside" code should look like this?

     <img src="<perch:shop id="parent.image_secondary" type="image" width="800" height="800" density="1.6" crop="true" />"