Environment Details
Hugo Static Site Generator v0.55.4 linux/amd64 BuildDate: 2019-04-25T10:10:44Z
GOOS="linux"
GOARCH="amd64"
GOVERSION="go1.12.2"
Error
I’m trying to create a data template to range over a JSON array in one of my ~/data
files, but I’m stuck on the following error:
... execute of template failed: template: ... at <$quote>: range can't iterate over $.Site.Data.quotes.person.lines
… but what am I doing wrong to keep Hugo from iterating over what is, in fact, an array?
JSON Schema
From ~/data/quotes.json
, clearly showing person.lines
as an array:
{
"person": {
"lines": [
"first line of trenchant prose",
"second line",
"don’t forget this line",
"long-winded author",
"last line."
]
}
}
I’m referencing the person
key as a front matter value in my templates and making it the context inside the partial template (the template throwing the error).
Template
<blockquote>
{{ $quote := . }}
{{ range (printf "$.Site.Data.quotes.%s.lines" $quote) }}
<span>{{ . }}</span>
{{ end }}
</blockquote>
I don’t think it’s a context issue, since I’m able to access the $quote
with the dot
, as suggested by the error text. So, I’m stumped.
Please advise.
Thanks for your help.