I want to read all of them and merge the things lists into one (so far I’ve done it) and I also want to attach a new key-value for every one of them in the process.
I have the following code, where $data is the name of the yaml file from the outer loop.
Have you tried reproducing the issue with different formats than YAML?
Apart from this, you can alter your logic to loop through the actual items with a second loop. This works:
{{/* Initialize "results" so it does not hold old values */}}
{{ $.Scratch.Set "results" (dict "apple" 0) }}
{{ range index .Site.Data.items "things" }}
{{ range $i, $j := . }}
{{ $x := $.Scratch.Get "results" }}
{{ if isset $x $i }}
{{/* This item is already initialized, we can add! */}}
{{ $.Scratch.SetInMap "results" $i (add $j (index $x $i)) }}
{{ else }}
{{ $.Scratch.SetInMap "results" $i $j }}
{{ end }}
{{ end }}
{{ end }}
{{ $.Scratch.Get "results" }}