Range over data integer key

I have a yaml file containing years as keys of an array.

  foo: bar
  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?

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.


i understand, thanks

3 posts were split to a new topic: Comment and summarize code examples