# "len of untyped nil" on list I can successfully range over

**URL:** https://discourse.gohugo.io/t/len-of-untyped-nil-on-list-i-can-successfully-range-over/12780
**Category:** support
**Created:** [July 6, 2018, 8:39pm UTC](https://discourse.gohugo.io/t/len-of-untyped-nil-on-list-i-can-successfully-range-over/12780 "2018-07-06T20:39:00Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![markhuge](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/markhuge/32/6345_2.png) [@markhuge](https://discourse.gohugo.io/u/markhuge)
#### Post date: [July 6, 2018, 8:39pm UTC](https://discourse.gohugo.io/t/len-of-untyped-nil-on-list-i-can-successfully-range-over/12780/1 "2018-07-06T20:39:00Z")

</div>

I’m writing a new theme from scratch. I have a single `index.html` and a single partial. This is `index.html` in its entirety:

```
 {{ $paginate := .Paginate (where .Site.Pages "Type" "post") }}
  {{ range $paginate.Pages }}
    {{ partial "detail.html" . }}
  {{ end }}

```

And this is the `detail.html` partial:

```
 <div class="tags">
        {{ $total := len .Params.tags }}
        {{ range $i, $tag := .Params.tags }} // this works if I remove the line above
        <a href="{{ "/tags/" | relURL }}{{ $tag |urlize}}">{{ $tag }}&nbsp;</a>
        {{ end }}
  </div>

```

I’m able to range over `.Params.tags` without issue, but calling `len` on `.Params.tags` throws:

```
 at <len .Params.tags>: error calling len: len of untyped nil

```

Content example:

```markdown
---
title: "Test"
date: 2018-07-18:37:59-07:00
tags: ["test"]
draft: false
---

WTF

```

hugo env:

```
 Hugo Static Site Generator v0.42.2 linux/amd64 BuildDate: 2018-07-02T23:39:55+0200
 GOOS="linux"
 GOARCH="amd64"
 GOVERSION="go1.10.3"
```

---

<div class="post-metadata">

### Author: ![RickCogley](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rickcogley/32/10269_2.png) [@RickCogley](https://discourse.gohugo.io/u/RickCogley)
#### Post date: [July 6, 2018, 9:02pm UTC](https://discourse.gohugo.io/t/len-of-untyped-nil-on-list-i-can-successfully-range-over/12780/2 "2018-07-06T21:02:15Z")

</div>

Untested wild guess: does the Param you’re testing for exist on all content? In other contexts “with” helps this.

---

<div class="post-metadata">

### Author: ![markhuge](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/markhuge/32/6345_2.png) [@markhuge](https://discourse.gohugo.io/u/markhuge)
#### Post date: [July 6, 2018, 9:24pm UTC](https://discourse.gohugo.io/t/len-of-untyped-nil-on-list-i-can-successfully-range-over/12780/3 "2018-07-06T21:24:34Z")

</div>

The content is only that single example post, so can confirm it’s not from missing tag frontmatter. However `{{ with .Params.tags }}` produces a new error:

`can't evaluate field Params in type []string`

I’m getting the same issue when I try it as toml frontmatter as well:

```auto
+++
title = "Test"
date = "2018-07-18:37:59-07:00"
tags = ["test"]
draft = false
+++

```

For some reason it evaluates properly with `range` but not `with` or `len`

---

<div class="post-metadata">

### Author: ![markhuge](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/markhuge/32/6345_2.png) [@markhuge](https://discourse.gohugo.io/u/markhuge)
#### Post date: [July 6, 2018, 9:42pm UTC](https://discourse.gohugo.io/t/len-of-untyped-nil-on-list-i-can-successfully-range-over/12780/4 "2018-07-06T21:42:37Z")

</div>

Super odd, if I add `{{ printf "%#v" .Params.tags}}`

I get `[]string{"test"}` so it’s getting populated for sure

Also in the top example I use `.Site.Pages` which does include a top level “Posts” obj without tags, but using `.Data.Pages` doesn’t, and produces the same result.

---

<div class="post-metadata">

### Author: ![Lucantas](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/lucantas/32/8920_2.png) [@Lucantas](https://discourse.gohugo.io/u/Lucantas)
#### Post date: [June 11, 2019, 9:17pm UTC](https://discourse.gohugo.io/t/len-of-untyped-nil-on-list-i-can-successfully-range-over/12780/5 "2019-06-11T21:17:35Z")

</div>

Have you figured it out this problem?

---

<div class="post-metadata">

### Author: ![markhuge](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/markhuge/32/6345_2.png) [@markhuge](https://discourse.gohugo.io/u/markhuge)
#### Post date: [June 11, 2019, 9:38pm UTC](https://discourse.gohugo.io/t/len-of-untyped-nil-on-list-i-can-successfully-range-over/12780/6 "2019-06-11T21:38:56Z")

</div>

I did not

---

<div class="post-metadata">

### Author: ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)
#### Post date: [June 11, 2019, 11:16pm UTC](https://discourse.gohugo.io/t/len-of-untyped-nil-on-list-i-can-successfully-range-over/12780/7 "2019-06-11T23:16:12Z")

</div>

I know that the original question is from ages ago, but have you tried `.Page.Params.tags` from within the partial?

This seems like a scoping issue.

---

<div class="post-metadata">

### Author: ![BigBadBaz](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@BigBadBaz](https://discourse.gohugo.io/u/BigBadBaz)
#### Post date: [July 30, 2020, 4:55am UTC](https://discourse.gohugo.io/t/len-of-untyped-nil-on-list-i-can-successfully-range-over/12780/8 "2020-07-30T04:55:07Z")

</div>

I have exactly the same issue. I have this code:

```auto
{{ $pgs := .Param "componentOf" }}
{{ printf "Variable: %#v\n" $pgs }}

```

It generates either `[]string{}` or `[]string{ "..." }`, yet:

```auto
{{ $pgs := .Param "componentOf" }}
{{ printf "Variable: %#v\n" $pgs }}

{{ $pgsc := len $pgs }}
{{ printf "%+v\n" $pgsc }}

```

causes:

```auto
Rebuild failed:

Failed to render pages: render of "section" failed: "/Users/bsheward/site/themes/genesis/layouts/service/list.html:15:40": execute of template failed: template: service/list.html:15:40: executing "main" at <len $pgs>: error calling len: reflect: call of reflect.Value.Type on zero Value

13 {{ printf "Variable: %#v\n" $pgs }}
14
15 {{ $pgsc := len $pgs }}
16 {{ printf "%+v\n" $pgsc }}

```

Surely len should return 0 if it is passed an empty string array, right?

---

<div class="post-metadata">

### Author: ![icanfathom](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/icanfathom/32/14774_2.png) [@icanfathom](https://discourse.gohugo.io/u/icanfathom)
#### Post date: [July 10, 2021, 3:44pm UTC](https://discourse.gohugo.io/t/len-of-untyped-nil-on-list-i-can-successfully-range-over/12780/9 "2021-07-10T15:44:18Z")

</div>

I encountered the same error. In my case, the tags were not defined for some posts, so it was failing to process those (even though the single file I was testing on had tags aplenty). Testing using ‘with’ first fixed it.

---

<div class="post-metadata">

### Author: ![pointyfar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pointyfar/32/5797_2.png) [@pointyfar](https://discourse.gohugo.io/u/pointyfar)
#### Post date: [July 11, 2021, 12:40am UTC](https://discourse.gohugo.io/t/len-of-untyped-nil-on-list-i-can-successfully-range-over/12780/10 "2021-07-11T00:40:51Z")

</div>


