Doing {{ index .Site.Author .Params.author }}
causes an error:
execute of template failed at <index site.Author .Params.author>: error calling index: value is nil; should be of type string
I checked, and no value is nil. See below. Indexing with an identical string literal does work.
config.yaml:
author:
george_bluth:
display_name: George Bluth
michael_bluth:
display_name: Michael Bluth
Front matter:
+++
author = "michael_bluth"
foo = "michael_bluth"
Template:
<p>.Site.Author: {{ .Site.Author }}</p>
<p>printf "%T" .Site.Author: {{ printf "%T" .Site.Author }}</p>
<p>.Params.author: {{ .Params.author }}</p>
<p>printf "%T" .Params.author: {{ printf "%T" .Params.author }}</p>
<p>eq .Params.author "michael_bluth": {{ eq .Params.author "michael_bluth" }}</p>
<p>index .Site.Author "michael_bluth": {{ index .Site.Author "michael_bluth" }}</p>
Output:
.Site.Author: map[george_bluth:map[display_name:George Bluth] michael_bluth:map[display_name:Michael Bluth]]
printf "%T" .Site.Author: map[string]interface {}
.Params.author: michael_bluth
printf "%T" .Params.author: string
eq .Params.author "michael_bluth": true
index .Site.Author "michael_bluth": map[display_name:Michael Bluth]
Note that {{ index .Site.Author .Params.foo }}
also results in the same error.
Sorry in advance if I’m missing something obvious, but after a half hour of debugging, I just can’t see it.
Full verbose error output
ERROR 2022/12/19 15:11:54 render of "taxonomy" failed: "/Users/Will/Developer/paige/layouts/_default/taxonomy.html:2:3": execute of template failed: template: _default/taxonomy.html:2:3: executing "main" at <partial "paige-article.html" .>: error calling partial: "/Users/Will/Developer/paige/layouts/partials/paige-article.html:4:7": execute of template failed: template: partials/paige-article.html:4:7: executing "partials/paige-article.html" at <partial "paige-authors.html" .>: error calling partial: "/Users/Will/Developer/paige/layouts/partials/paige-authors.html:4:3": execute of template failed: template: partials/paige-authors.html:4:3: executing "partials/paige-authors.html" at <index .Site.Author .Params.author>: error calling index: value is nil; should be of type string
Error: Error building site: failed to render pages: render of "page" failed: "/Users/Will/Developer/paige/layouts/_default/paige-search.html:2:3": execute of template failed: template: _default/paige-search.html:2:3: executing "main" at <partial "paige-article.html" .>: error calling partial: "/Users/Will/Developer/paige/layouts/partials/paige-article.html:4:7": execute of template failed: template: partials/paige-article.html:4:7: executing "partials/paige-article.html" at <partial "paige-authors.html" .>: error calling partial: "/Users/Will/Developer/paige/layouts/partials/paige-authors.html:4:3": execute of template failed: template: partials/paige-authors.html:4:3: executing "partials/paige-authors.html" at <index .Site.Author .Params.author>: error calling index: value is nil; should be of type string
What version of Hugo are you using (hugo version
)?
$ hugo version
hugo v0.108.0+extended darwin/amd64 BuildDate=unknown
Does this issue reproduce with the latest release?
Yes