# \[SOLVED\] Error calling index: value is nil; should be of type string

**URL:** <https://discourse.gohugo.io/t/solved-error-calling-index-value-is-nil-should-be-of-type-string/10453>\
**Category:** support\
**Created:** [February 9, 2018, 5:42pm UTC](https://discourse.gohugo.io/t/solved-error-calling-index-value-is-nil-should-be-of-type-string/10453 "2018-02-09T17:42:04Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hash\_Borgir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/hash_borgir/32/6655_2.png) [@Hash\_Borgir](https://discourse.gohugo.io/u/Hash_Borgir)\
**Post date:** [February 9, 2018, 5:42pm UTC](https://discourse.gohugo.io/t/solved-error-calling-index-value-is-nil-should-be-of-type-string/10453/1 "2018-02-09T17:42:04Z")

</div>

> Template changed “/home/stoned/websites/websites/psychedelicsdaily.com-hugo/themes/hugo-universal-theme/layouts/partials/css.html”: CREATE  
> ERROR 2018/02/09 10:18:46 Error while rendering “taxonomyTerm” in “”: template: theme/\_default/list.html:49:45: executing “theme/\_default/list.html” at \<index .Site.Params.a…\>: error calling index: value is nil; should be of type string

Is the error I get. This is the line in question: `{{$author := index .Site.Params.authors (.Params.author) }}`

This only started to happen after I upgraded my Hugo. I forgot what the older version was.

config.toml has

`author=authors as taxonomy`

Article front matter has

```
+++
author="hash"
authors="hash-borgir"
+++

```

and the config.toml file has

`[params.authors.hash]`

`{{$author := index .Site.Params.authors (.Params.author)}}` works in single.html (single page template), but when in list.html, it gives an error.

Could it be that single.html can read the article front matter, in which .Params.author is defined as front matter author=“hash” cannot?

I’m guessing list.html template pages can’t read article front matter of pages? I’ve tried something like:

```
{{ range .Data.Pages }}
     {{$author := index .Site.Params.authors (.Params.author)}}
{{ end }}

```

and that still gives me the error.

That code giving the error: `<index .Site.Params.a...>: error calling index: value is nil; should be of type string` basically expects `(.Params.author)` to be a thing, which it is not, hence the nil error.

`.Site.Params.authors` defines an array of authors. Article front matter` author=""` bit `(.Params.author)` is the actual author in the .Site.Params.authors array.

How can I make list template pages get access to `.Params.author`?

Note: This only gives an error in Hugo logs, but actually continues to function… for some odd reason.

If you go to [hash-borgir - Using Psychedelics Daily for a happy & healthy life](https://www.psychedelicsdaily.com/authors/hash-borgir) or [Dimethyltryptamine (DMT) - Using Psychedelics Daily for a happy & healthy life](https://www.psychedelicsdaily.com/tags/dmt) you’ll see the list pages, and how each author is properly functioning, but I still get this error, and I’d like to not have this error anymore.

Let me know what else I can help you to do understand my problem. Please advise, guys.

Sincerely,

Hash B.

---

<div class="post-metadata">

**Author:** ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)\
**Post date:** [February 9, 2018, 5:45pm UTC](https://discourse.gohugo.io/t/solved-error-calling-index-value-is-nil-should-be-of-type-string/10453/2 "2018-02-09T17:45:50Z")

</div>

> [@Hash\_Borgir](#):
>
> This only started to happen after I upgraded my Hugo. I forgot what the older version was.

It would help to know from which version to which you upgraded.

But in any case…

> [@](#):
>
> This is the line in question: {{$author := index .Site.Params.authors (.Params.author) }}

> [@](#):
>
> Article front matter has
> 
> ```auto
> +++
> author="hash"
> authors="hash-borgir"
> +++
> 
> ```

You are using `.Site.Params.`…, but setting the parameters in the page. If you want to access the page params, use just `.Params`.

`.Site.Params` would be the ones you define in `[Params]` in your `config.toml`.

**Update** : Nevermind, I see that you have that part set correctly…

Then may be you don’t set the same front-matter in the section `_index.md` files too, and that’s the problem?

---

<div class="post-metadata">

**Author:** ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)\
**Post date:** [February 9, 2018, 5:50pm UTC](https://discourse.gohugo.io/t/solved-error-calling-index-value-is-nil-should-be-of-type-string/10453/3 "2018-02-09T17:50:17Z")

</div>

On another note, I am a fan of `with`, so that you don’t try to access stuff that is not defined… how about something like:

```auto
{{ with .Params.author }}
    {{ $author := index $.Site.Params.authors {{ . }} }}
    /* more logic */
{{ end }}

```

---

<div class="post-metadata">

**Author:** ![Hash\_Borgir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/hash_borgir/32/6655_2.png) [@Hash\_Borgir](https://discourse.gohugo.io/u/Hash_Borgir)\
**Post date:** [February 9, 2018, 5:50pm UTC](https://discourse.gohugo.io/t/solved-error-calling-index-value-is-nil-should-be-of-type-string/10453/4 "2018-02-09T17:50:50Z")

</div>

I thought about that \_index.html bit, but if I do

\_index.md

+++  
author=“hash”  
+++

I will be able to put “hash” `(.Params.author)` into `.Site.Params.authors` so I can retrieve the values for that author, but then each \_index.md will only show one author.

.Site.Params.authors is multiple authors:

```
In config.toml

[params.authors.hash]
[params.authors.augustine]
[params.authors.guest]
```

---

<div class="post-metadata">

**Author:** ![Hash\_Borgir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/hash_borgir/32/6655_2.png) [@Hash\_Borgir](https://discourse.gohugo.io/u/Hash_Borgir)\
**Post date:** [February 9, 2018, 5:53pm UTC](https://discourse.gohugo.io/t/solved-error-calling-index-value-is-nil-should-be-of-type-string/10453/5 "2018-02-09T17:53:22Z")

</div>

A list page shows 2 pages for example.

Page 1 is by author.hash  
Page 2 is by author.augustine

How do I make list.html (list templates) go into each page that it lists, into that page’s front matter, and access that page’s .Params.author?

That’s what I need to do.

I need access to every single list item in the list template’s front matter. Each article could have a diff author. I need access to that.

Does this make sense?

EDIT: For example

`{{$author := index .Site.Params.authors (.Params.author AS DEFINED IN THE ARTICLE'S FRONTMATTER) }}`

How would this be?

.Site.Params.authors(.Page.Parmams.author) ? Something like that anyway.

---

<div class="post-metadata">

**Author:** ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)\
**Post date:** [February 9, 2018, 5:56pm UTC](https://discourse.gohugo.io/t/solved-error-calling-index-value-is-nil-should-be-of-type-string/10453/6 "2018-02-09T17:56:23Z")

</div>

I see that you updated the snippet in the original post. Now it shows:

> [@](#):
>
> ```auto
> {{ range .Data.Pages }}
> {{$author := index .Site.Params.authors (.Params.author)}}
> {{ end }}
> 
> ```

So that would then just loop through regular pages (not sections).

If even then you get that error, then one of the pages doesn’t have the `author` defined in front-matter.

---

<div class="post-metadata">

**Author:** ![Hash\_Borgir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/hash_borgir/32/6655_2.png) [@Hash\_Borgir](https://discourse.gohugo.io/u/Hash_Borgir)\
**Post date:** [February 9, 2018, 5:57pm UTC](https://discourse.gohugo.io/t/solved-error-calling-index-value-is-nil-should-be-of-type-string/10453/7 "2018-02-09T17:57:35Z")

</div>

Hmm. Actually it should be .RegularPages, right, so \_index.md doesn’t get listed?

---

<div class="post-metadata">

**Author:** ![Hash\_Borgir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/hash_borgir/32/6655_2.png) [@Hash\_Borgir](https://discourse.gohugo.io/u/Hash_Borgir)\
**Post date:** [February 9, 2018, 5:59pm UTC](https://discourse.gohugo.io/t/solved-error-calling-index-value-is-nil-should-be-of-type-string/10453/8 "2018-02-09T17:59:56Z")

</div>

All the content pages have author defined afaict.

---

<div class="post-metadata">

**Author:** ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)\
**Post date:** [February 9, 2018, 6:01pm UTC](https://discourse.gohugo.io/t/solved-error-calling-index-value-is-nil-should-be-of-type-string/10453/9 "2018-02-09T18:01:00Z")

</div>

> [@Hash\_Borgir](#):
>
> Actually it should be .RegularPages

~~You are probably right!~~ I haven’t yet played much with those. Just try it out 🙂

* * *

**Update**

Nope, looks like `.Data.Pages` lists only regular pages.

Tried by putting this in my `index.html`:

```auto
{{ range .Data.Pages }}
     {{ partial "debugprint.html" (slice .Kind .Title) }}<br>
{{ end }}

```

[`debugprint.html` partial](https://github.com/kaushalmodi/hugo-bare-min-theme/blob/master/layouts/partials/debugprint.html)

* * *

**Update 2**

You can even extend that to:

```auto
{{ range .Data.Pages }}
    {{ if .Params.author }}
        <b>Author is {{ .Params.author }} for {{ partial "debugprint.html" (slice .Kind .Title) }}</b><br>
    {{ else }}
        No author for {{ partial "debugprint.html" (slice .Kind .Title) }}<br>
    {{ end }}
{{ end }}

```

That gives me this on my site:

![image](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/2X/f/f4c298fa94556d6a6e7b28f3d4aa57ed3d577e98.png)

---

<div class="post-metadata">

**Author:** ![Hash\_Borgir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/hash_borgir/32/6655_2.png) [@Hash\_Borgir](https://discourse.gohugo.io/u/Hash_Borgir)\
**Post date:** [February 9, 2018, 6:15pm UTC](https://discourse.gohugo.io/t/solved-error-calling-index-value-is-nil-should-be-of-type-string/10453/10 "2018-02-09T18:15:03Z")

</div>

In \_default/list.html

I changed my paginator to `.Paginate .Site.RegularPages`

I think .Data.Pages was pulling the \_index.md pages in my content categories which don’t all always have author="" bit defined.

```auto
{{ $paginator := .Paginate .Site.RegularPages }}

```

I don’t see any more errors in the log. Page seems to work fine. But now ever taxonomy shows all the site pages.

So, is there something like`.Data.RegularPages` (I can’t use `.Site.Pages` or Site.RegularPages because I need to stay within the paginator context .Data).

I still struggle with hugo template syntax.

Is it possible to change this into whatever would give me:

Change

From: `{{ $paginator := .Paginate .Data.Pages }}`

To: `{{ $paginator := .Paginate .Data.Pages (WHERE .Data.Pages DOES NOT INCLUDE _index.md)}}` ?

I can’t figure out the “where” clause in this go syntax. Please advise.

EDIT: I came up with:

`{{ $paginator := .Paginate where .Data.Pages "!=" "_index.md" }}`

ERROR 2018/02/09 11:18:59 Error while rendering “taxonomy” in “tags/microdosing/”: template: theme/\_default/list.html:34:27: executing “theme/\_default/list.html” at : wrong number of args for where: want at least 2 got 0

`{{ $paginator := .Paginate where .Data.Pages .File.BaseFileName "!=" "_index.md" }}`

Template changed “/home/stoned/websites/websites/psychedelicsdaily.com-hugo/themes/hugo-universal-theme/layouts/\_default/list.html”: CREATE  
ERROR 2018/02/09 11:20:05 Error while rendering “taxonomy” in “tags/microdosing/”: template: theme/\_default/list.html:34:27: executing “theme/\_default/list.html” at : wrong number of args for where: want at least 2 got 0

Dang nabbit. I can’t figure this one out alone.

---

<div class="post-metadata">

**Author:** ![Hash\_Borgir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/hash_borgir/32/6655_2.png) [@Hash\_Borgir](https://discourse.gohugo.io/u/Hash_Borgir)\
**Post date:** [February 9, 2018, 6:37pm UTC](https://discourse.gohugo.io/t/solved-error-calling-index-value-is-nil-should-be-of-type-string/10453/11 "2018-02-09T18:37:05Z")

</div>

```auto
{{ $paginator := .Paginate .Data.Pages }}
{{ range $i, $e := where ($paginator.Pages) ".Params.hidden" "!=" true }}
<section class="post shadow box">
<div class="row">
    <div class="col-md-4">
        <div class="image shadow">
            <a href="{{ .Permalink }}">
                {{ if .Params.banner }}
                <img src="{{ .Site.BaseURL}}img/placeholder.png" data-src="{{ .Site.BaseURL}}{{ .Params.banner }}" class="img-responsive" alt="">
                {{ else }}
                <img src="{{ .Site.BaseURL}}img/placeholder.png" class="img-responsive" alt="">
                {{ end }}
            </a>
        </div>
    </div>

    <div class="col-md-8 post-meta">
        <h2><a href="{{ .Permalink }}">{{ .Title }}</a></h2>
        <div class="clearfix">
            <p class="author-category">
                {{ if isset .Params "author" }}
                {{$author := index .Site.Params.authors (.Params.author) }}
                <a class="" href="{{$baseurl}}authors/{{ .Params.authors | urlize }}/"><i class="fa fa-user" aria-hidden="true"></i>{{$author.display_name}}</a>
                {{ end }}

            {{ range $index, $tag := .Params.tags }}
            <a class="" href="{{$baseurl}}tags/{{ $tag | urlize }}/"><i class="fa fa-hashtag" aria-hidden="true"></i>{{ $tag }}</a>,
            {{ end }}

                {{ if isset .Params "categories" }}
                {{ if gt (len .Params.categories) 0 }}
                <a href="{{ $.Site.BaseURL }}categories/{{ index .Params.categories 0 | urlize | lower }}"><i class="fa fa-folder" aria-hidden="true"></i>{{ index .Params.categories 0 }}</a>
                {{ end }}
                {{ end }}

            </p>
            <p class="date-comments">
                <a href="{{ .Permalink }}"><i class="fa fa-clock-o"></i> {{ .Date.Format .Site.Params.date_format }}</a>
            </p>
        </div>

        <p class="read-more"><a href="{{ .Permalink }}" class="btn btn-template-main shadow"><i class="fa fa-list-alt" aria-hidden="true"></i> {{ i18n "continueReading" }}</a>
        </p>
    </div>
</div>
</section>
{{ end }}

```

I moved the author bits under the if sanity check. Now error goes away and everything seemingly still functions.

---

<div class="post-metadata">

**Author:** ![Hash\_Borgir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/hash_borgir/32/6655_2.png) [@Hash\_Borgir](https://discourse.gohugo.io/u/Hash_Borgir)\
**Post date:** [February 9, 2018, 6:40pm UTC](https://discourse.gohugo.io/t/solved-error-calling-index-value-is-nil-should-be-of-type-string/10453/12 "2018-02-09T18:40:19Z")

</div>

Just checking out the debug partial! Superb work. Thanks for taking the time to help me look.

---

<div class="post-metadata">

**Author:** ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)\
**Post date:** [February 9, 2018, 6:53pm UTC](https://discourse.gohugo.io/t/solved-error-calling-index-value-is-nil-should-be-of-type-string/10453/13 "2018-02-09T18:53:10Z")

</div>

> [@Hash\_Borgir](#):
>
> I think .Data.Pages was pulling the \_index.md pages in my content categories which don’t all always have author=“” bit defined.

That’s very odd. I cannot recreate that… `.Data.Pages` pulls in only regular pages for me (no section content pages). May be @bep can chime in for clarification.

> [@Hash\_Borgir](#):
>
> I moved the author bits under the if sanity check. Now error goes away and everything seemingly still functions.

Cool! Though, once you get comfortable with the `with` syntax, you’ll stop using `if` and `isset` where possible 😄

* * *

On a slightly tangential note, @regis has written this excellent blog post [on **dot**](https://regisphilibert.com/blog/2018/02/hugo-the-scope-the-context-and-the-dot/)… _I am mentioning this post because you will come across this concept if you start using `with`._

* * *

> [@Hash\_Borgir](#):
>
> Just checking out the debug partial! Superb work.

Thanks. It’s a growing piece of work… As I come across debugging types that aren’t automatically detected as a map or slice, I update it.

---

<div class="post-metadata">

**Author:** ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)\
**Post date:** [February 9, 2018, 7:10pm UTC](https://discourse.gohugo.io/t/solved-error-calling-index-value-is-nil-should-be-of-type-string/10453/14 "2018-02-09T19:10:49Z")

</div>

Just to answer this question that went unresolved:

> [@Hash\_Borgir](#):
>
> ```auto
> {{ $paginator := .Paginate where .Data.Pages "!=" "_index.md" }}
> 
> ```
> 
> ERROR 2018/02/09 11:18:59 Error while rendering “taxonomy” in “tags/microdosing/”: template: theme/\_default/list.html:34:27: executing “theme/\_default/list.html” at : wrong number of args for where: want at least 2 got 0

The fix is to provide **“string”** arguments (except the first argument) to the `where` function.

So if you want to list everything except for the pages whose `.Kind` is `"section"`, you’d do the below (yes, using `"Kind"` instead of `.Kind`, and `"ne"` instead of `ne`):

```auto
{{ $paginator := .Paginate (where .Site.Pages "Kind" "ne" "section") }}

```
