In a partial template, the following works OK - i.e. .renders as desired:
{{if .Site.Params.Author}}
{{ $.Scratch.Set "authorname" .Site.Params.Author }}
{{ end }}
{{ $fields := getJSON "data.json" }}
{{ if index $fields ($.Scratch.Get "authorname") }}
{{ $.Scratch.Set "authorbio" ( index $fields ($.Scratch.Get "authorname") ) }}
{{ else }}
{{ $.Scratch.Set "authorbio" ( index $fields "unknown" ) }}
{{ end }}
<img src="{{ index ( $.Scratch.Get "authorbio" ) "thumb" }}" /">
But this code:
{{ index ( $.Scratch.Get "authorbio" ) "thumb" }}
Always generates the following error:
ERROR: 2016/09/19 17:02:39 template.go:131: template: theme/partials/author.html:19:14: executing "theme/partials/author.html" at <index ($.Scratch.Get...>: error calling index: index of untyped nil in theme/partials/author.html
Since img src
is correctly set to the author-specific contents of thumb
each time the partial is called, any idea what might be causing the error? https://discuss.gohugo.io/t/listing-members-of-a-taxonomy-in-shortcode/3697/14 suggests it might be down to Hugo version and/or issue 2303; we’re at 0.16 and 2303 now seems closed.
Many thanks in advance for any help.