Forum

Thread tagged as: Question

JSON loop using repeaters

I want to create a JSON loop using repeaters. I can get most of the way but can't figure out how to leave off a comma-separator for the last items.

For example:

    <perch:repeater id="images" label="Images" scope-parent="true">
        <perch:every nth-child="1">         
            <img src="<perch:content type="image" id="image" label="Image" />" alt="<perch:content type="text" id="image_alt" label="Supporting text" />" />        
            <script class="other-slides" type="text/cycle">
            [
        <perch:else />  
            "<img src='<perch:content type="image" id="image" label="Image" />' alt='<perch:content type="text" id="image_alt" label="Supporting text" />' />",
            <perch:after>
            ]
            </script>
            </perch:after>
        </perch:every>      
    </perch:repeater>

With the trailing comma on the last entry the entry is invalidated.

Any thoughts appreciated …

Cole Henley

Cole Henley 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

<perch:if not-exists="perch_item_last">,</perch:if>

Marvellous, worked. Thanks Drew!