Position Indicators - How to set starting index of $Pos?

<%- if @topic_view.topic.tags.present? %>
<%= t 'js.tagging.tags' %>: <%- @topic_view.topic.tags.each do |t| %> <%= t %> <%- end %>
<% end %>

Silverstripe Version: 4.8


In the CMS Doc guide: https://docs.silverstripe.org/en/4/developer_guides/templates/syntax/#position-indicators

It says

$Pos : The current position in the list (integer). Will start at 1, but can take a starting index as a parameter.

I’m using $Pos as the iterator ID of a loop and i need it to start at zero… however i can’t find anywhere how to define the starting index of $Pos.

How do i start $Pos at Zero?
Where do i put it/ define it in conjunction to the <% loop … %> that i’m using it for?

<% loop $feature %>    

        <button data-bs-target="#carouselWidget" data-bs-slide-to="**$Pos**" aria-label="Go to slide **$Pos**" ></button>

<% end_loop %>


You specify it as a parameter: $Pos(0) - this just tells the iterator to start its numbers at 0 instead of 1.

The $Pos will be available anywhere inside the loop, and will return the current position in the loop, you don’t need to define it.

<% loop $feature %>
  <button data-bs-slide-to="$Pos(0)"></button>
<% end_loop %>

Would result in:

<button data-bs-slide-to="0"></button>
<button data-bs-slide-to="1"></button>
<button data-bs-slide-to="2"></button>
<button data-bs-slide-to="3"></button>

Thank you @DorsetDigital.

My logic got in the way :roll_eyes: … i use $Pos in multiple locations in the same <% loop %> and i was looking to start/define it once before the loop (which is how i would originally define a count iterator in a php loop)

In my original question I simplified my example code for brevity, but your answer got me to where i needed… for the benefit of other people who may find this… what my actual solution is:

<% loop $featureCarousel %> 
	<% if $IsFirst %>
		<button data-bs-target="#carouselWidget" data-bs-slide-to="$Pos(0)" aria-label="Go to slide $Pos" class="active" aria-current="true" ></button>
	<% else %>
		<button data-bs-target="#carouselWidget" data-bs-slide-to="$Pos(0)" aria-label="Go to slide $Pos" ></button>
	<% end_if %>
<% end_loop %>

The above code outputs:

<div class="carousel-indicators">
    <button data-bs-target="#carouselWidget" data-bs-slide-to="0" aria-label="Go to slide 1" class=""></button>
    <button data-bs-target="#carouselWidget" data-bs-slide-to="1" aria-label="Go to slide 2" class="active" aria-current="true"></button>
    <button data-bs-target="#carouselWidget" data-bs-slide-to="2" aria-label="Go to slide 3" class=""></button>

Its awesome that you can use the same variable $Pos in multiple instances and give each one a unique start Index … you can see in my example the data-bs-slide-to variable starts at zero - but the aria-label starts at 1 (default) which makes more sense for a label.

Thanks again DorsetDigital.