betz
1
I have a yaml file containing years as keys of an array.
Like:
2018:
foo: bar
2019:
john: doe
But when I try {{ range .Site.Data.something.2018 }}
i get a fatal: “range can’t iterate over 0.2018”
2 questions:
- How can i have a integer as key and select this in my range?
- One step up, how can I interate over all years and have the key as variable to print?
zwbetz
2
On my phone, so this is obviously untested, but try something like:
{{ range .Site.Data.something }}
{{ . }}
{{ range $key, $value := . }}
{{ $key }} = {{ $value }}
{{ end }}
{{ end }}
Depending on how data file is arranged, you may have to add another nested range, or remove one.
2 Likes
maiki
Split this topic
4
3 posts were split to a new topic: Comment and summarize code examples