How counting up a variable in range

I found another method without depending on the index var which might be at times a string when having a dictionary, and also with being able to sort array…

  {{ $.Scratch.Set "counter" 0 }}
  {{range sort .Params.employees}}
    {{ $.Scratch.Set "counter" (add ($.Scratch.Get "counter") 1) }}
    I am the number {{$.Scratch.Get "counter"}} in loop!
  {{end}}
5 Likes