Given a slice / array I needed to loop over it and create arrays of equal sizes or to chunk the array. This is what I came up with. I haven’t seen examples with golang templates, what would you do to chunk a slice into individual slices of a set size?
{{ $testArrayToChunk := (slice "1" "2" "3" "4" "5" "6")}}
{{ $.Scratch.Add "testing" (slice) }}
{{ $.Scratch.Add "temp" (slice) }}
{{ range $k, $v := $testArrayToChunk }}
{{ $ck := (add $k 1) }}
{{ $newArray := mod $ck 2 }}
{{ if eq $newArray 0}}
{{ $.Scratch.Add "temp" (slice $v) }}
{{ $.Scratch.Add "testing" (slice ($.Scratch.Get "temp")) }}
{{ $.Scratch.Set "temp" (slice)}}
{{ else }}
{{ $.Scratch.Add "temp" (slice $v) }}
{{ end }}
{{ end }}