Hi, so for my site I’m trying to fit two values into one range, kinda like this
Frontmatter:
info:
- n: name1
y: 2023
- n: name2
y: 2023
Code:
{{ range .Params.info }}
Name {{ .n }}<br>
Year {{ .y }}<br><br>
{{ end }}
It doesn’t work though. I get this error:
execute of template failed at <.n>: can’t evaluate field n in type string
Where am I going wrong here?
Also this is where I found the solution I’m trying to use if it matters:
Hugo’s YAML interpreter is a bit out of date, where n is false and y is true, so this:
info:
- n: name1
y: 2023
- n: name2
y: 2023
is interpreted as:
[map[false:name1 true:2023] map[false:name2 true:2023]]
Quote the keys:
info:
- "n": name1
"y": 2023
- "n": name2
"y": 2023
The early YAML spec mapped all kinds of things to true and false. Norway got the sharp end of the stick on that one.
1 Like
Thank you for the reply!
Your solution worked for me. This helps a lot, I really appreciate it.
system
Closed
4
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.