Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Zero-based Loop counter


Go to End


3 Posts   1712 Views

Avatar
Spaghetti

Community Member, 32 Posts

21 November 2013 at 2:20am

This sounds silly and basic but I've been struggling with it for a while so, I need help...

All I'm trying to do is output some zero-based index values for some tags I need for my carousel object. These index pictures. I've got everything working except I can't find a simple way to output a zero-based value for the $Pos bit in the code below:

    <ol id="carousel-controls" class="carousel-indicators">
        <% loop $Photos %>
            <li data-target="#myCarousel" data-slide-to="$Pos-1"></li>
        <% end_loop %>
    </ol>

This will (obviously) output data-slide-to values that look like 1-1, 2-1, 3-1, and not 0 1 2, like I want. Any ideas how to fix this?

I tried using {$Pos-1} but that seemed to cause a syntax error. I guess I misunderstood the docs there.

I don't think I can use a function because the value would be cached... wouldn't it?

I'm confused. Help please?

Avatar
Spaghetti

Community Member, 32 Posts

21 November 2013 at 4:26am

Apparently you can just pass (0) as a parameter to $Pos and it's then zero-based. I couldn't find where Pos was defined in the documentation though or any mention of this - found the answer in a post elsewhere.

Avatar
kinglozzer

Community Member, 187 Posts

22 November 2013 at 2:04am

FYI: http://api.silverstripe.org/3.1/class-SSViewer_BasicIteratorSupport.html#_Pos :)

You can just search for nearly all the template parameters like $Pos in the API docs