Forum

Thread tagged as: Question

Perch:if for Repeater number of items

Is there a way I can get a list of numbers to appear based on the number of items in my repeater? See my code I currently have which fails:

            <div class="row">       
                <ul class="col list-inline">
                        <perch:if id="perch_item_index" match="eq" value="1"><li><a href="#section1/slide1">01</a></li></perch:if>
                        <perch:if id="perch_item_index" match="eq" value="2"><li><a href="#section1/slide2">02</a></li></perch:if>
                        <perch:if id="perch_item_index" match="eq" value="3"><li><a href="#section1/slide3">03</a></li></perch:if>
                        <perch:if id="perch_item_index" match="eq" value="4"><li><a href="#section1/slide3">04</a></li></perch:if>
                        <perch:if id="perch_item_index" match="eq" value="5"><li><a href="#section1/slide5">05</a></li></perch:if>
                </ul>
            </div><!-- END ROW -->
        </div><!-- END PANEL -->
    </div>

    <perch:repeater id="horizontalslides" label="Project gallery" scope-parent="true" output="count">
    <div class="slide" data-anchor="slide<perch:content id="perch_item_index" type="hidden"  />" > 
        <div class="fp-bg" style="background-image: url(<perch:content type="image" id="slideimage" label="Slide image" width="1500">)"></div>              
    </div>
    <!-- END SLIDE -->
    </perch:repeater>   
James Tedder

James Tedder 0 points

  • 2 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You can use perch_item_count in the repeater to get the count of the number of items, I think. Do you see it with <perch:showall> ?

That worked - Thanks

I had to wrap the list inside the repeater though.

    <perch:repeater id="horizontalslides" label="Project gallery" max="6" >
    <perch:before>
            <div class="row">       
                <ul class="col list-inline">
                        <perch:if id="perch_item_count" match="gte" value="1"><li><a href="#section1/slide1">01</a></li></perch:if>
                        <perch:if id="perch_item_count" match="gte" value="2"><li><a href="#section1/slide2">02</a></li></perch:if>
                        <perch:if id="perch_item_count" match="gte" value="3"><li><a href="#section1/slide3">03</a></li></perch:if>
                        <perch:if id="perch_item_count" match="gte" value="4"><li><a href="#section1/slide3">04</a></li></perch:if>
                        <perch:if id="perch_item_count" match="gte" value="5"><li><a href="#section1/slide5">05</a></li></perch:if>
                        <perch:if id="perch_item_count" match="gte" value="6"><li><a href="#section1/slide5">06</a></li></perch:if>
                </ul>
            </div><!-- END ROW -->
        </div><!-- END PANEL -->
    </div>
    </perch:before>
    <div class="slide" data-anchor="slide<perch:content id="perch_item_index" type="hidden" />" > 
        <div class="fp-bg" style="background-image: url(<perch:content type="image" id="slideimage" label="Slide image" width="1500">)"></div>  

    </div>
    <!-- END SLIDE -->
    </perch:repeater>