Hugo 0.41 - check for last item in Site.Data.any sorted range


#1

I have the following snippet:

{{ range $index, $element := sort .Site.Data.team “weight” }}

I want to check when enumerating if the actual item is the last one.
I already tried several attempts, but all failed.

Do anyone knows how to check if actual item in Site.Data enumeration (when sorted) is the last item?!

Thanks in advance!
Cheers
Zcs


#2

So maybe you could do something like this (I’m leaving your sorting out for simplicity):

{{ $count := .Site.Data.team | len }}
{{ range $index, $element := .Site.Data.team }}

{{ $.Scratch.Add "i" 1 }}
{{ $i := $.Scratch.Get "i" }}

{{ if eq $count $i }}LAST {{ end }}

{{ end }}