Hugo

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

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:

---
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"

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

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:

+++
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

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.

Have you figured it out this problem?

I did not

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.