I’m getting an error when using delimit with an array built by Scratch
I have a variable $byline that lists author pages from a book reviews. I loop over that variable to pull the author name from the head matter of those pages:
{{ range $i, $v := $byline }}
{{ with $v.Params.byline }}{{ $.Scratch.SetInMap "names" . . }}{{ end }}
{{ end }}
Then I can output nice comma separated values using delimit:
I was on v0.37 and this worked fine. I upgraded to v0.39 to hopefully address another issue (calling {{ $.Scratch.Delete "names" }} was throwing an error) and the delimit line started giving this error:
ERROR 2018/04/21 15:07:30 Error while rendering "home" in "": template: theme/index-content.html:31:23: executing "theme/index-content.html" at <delimit ($.Scratch.G...>: error calling delimit: can't iterate over <nil>
Writing: {{ $.Scratch.GetSortedMapValues "names" }} outputs an array of author names as expected, and {{ range $.Scratch.GetSortedMapValues "names" }}{{ . }} {{ end }} iterates over the array and lists the names individually as expected, so the data seems correct and present.
To be honest, I’m a bit unclear (I’m still very slow at parsing Go syntax in my head), but this was an example from another entry on this board, and it solved the problem I was having. I think I took it to as “I need two arguments here, and it will be harmless to use current context for both of them”
The repository is public. Please pardon the mess. I’m porting my templates from a previous system, so the files are full of old commented-out code. It’s very, very hacky right now
There are only one or two, but this is a pattern I’m going to be using throughout the site to list books, tags, and other lists. It was just the first instance I reached.