I need to set a id to an incremented value, is there any way I can get the current count that I’m on OR increment my own value each loop?
Currently my way of doing it is:
{{ $count := 0 }}
{{ range .Pages }}
{{ $count = add $count 1 }}
{{end}}
I need to set a id to an incremented value, is there any way I can get the current count that I’m on OR increment my own value each loop?
Currently my way of doing it is:
{{ $count := 0 }}
{{ range .Pages }}
{{ $count = add $count 1 }}
{{end}}
{{ range $iteration, $value := .Pages }}
{{ $value }}
{{ $iteration }}
{{ end }}
$value is what the dot .
was before, $iteration should increase starting from zero. But your way is right too.
On a related note: ID
as such, if you want to have a real unique identification method for example an article - try this:
<article{{ with .File }} id="x{{ .UniqueID }}"{{ end }}>