# Can't index .Site.Author with Page.Params.author

**URL:** <https://discourse.gohugo.io/t/cant-index-site-author-with-page-params-author/42003>\
**Category:** support\
**Created:** [December 19, 2022, 11:30pm UTC](https://discourse.gohugo.io/t/cant-index-site-author-with-page-params-author/42003 "2022-12-19T23:30:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![will](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/will/32/18403_2.png) [@will](https://discourse.gohugo.io/u/will)\
**Post date:** [December 19, 2022, 11:30pm UTC](https://discourse.gohugo.io/t/cant-index-site-author-with-page-params-author/42003/1 "2022-12-19T23:30:29Z")

</div>

Doing `{{ index .Site.Author .Params.author }}` causes an error:

```auto
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:

```auto
author:
  george_bluth:
    display_name: George Bluth
  michael_bluth:
    display_name: Michael Bluth

```

Front matter:

```auto
+++
author = "michael_bluth"
foo = "michael_bluth"

```

Template:

```auto
<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:

```auto
.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

```auto
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`)?

```auto
$ hugo version
hugo v0.108.0+extended darwin/amd64 BuildDate=unknown

```

### Does this issue reproduce with the latest release?

Yes

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [December 19, 2022, 11:43pm UTC](https://discourse.gohugo.io/t/cant-index-site-author-with-page-params-author/42003/2 "2022-12-19T23:43:27Z")

</div>

I will look at this in a bit, but with this in mind…

[https://github.com/gohugoio/hugoDocs/commit/2c0125b5290494d49334606c451446ebd9df3c21](https://github.com/gohugoio/hugoDocs/commit/2c0125b5290494d49334606c451446ebd9df3c21)

… I wouldn’t use `.Site.Author`.

Instead, I would use (in order of preference):

1. Hugo’s taxonomy system
2. Something in site configuration under the `params` key (e.g., `[params.authors]`)
3. A data file (e.g., `site.Data.authors.jdoe`)

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [December 19, 2022, 11:52pm UTC](https://discourse.gohugo.io/t/cant-index-site-author-with-page-params-author/42003/3 "2022-12-19T23:52:22Z")

</div>

One or more of the content pages rendered by this template does not define `author` in front matter.

You need to code defensively:

```plaintext
{{ with .Params.author }}
  {{ index site.Author . "display_name" }}
{{ end }}

```

---

<div class="post-metadata">

**Author:** ![will](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/will/32/18403_2.png) [@will](https://discourse.gohugo.io/u/will)\
**Post date:** [December 20, 2022, 12:30am UTC](https://discourse.gohugo.io/t/cant-index-site-author-with-page-params-author/42003/4 "2022-12-20T00:30:33Z")

</div>

@jmooring Thanks, that must have been it!

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [December 22, 2022, 12:30am UTC](https://discourse.gohugo.io/t/cant-index-site-author-with-page-params-author/42003/5 "2022-12-22T00:30:58Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
