Passing variables to a taxonomy partial

Hugo Static Site Generator v0.20.7 darwin/amd64 BuildDate: 2017-05-11T23:05:23-04:00

Take the following partial:

{{ $tags := $.Site.Taxonomies.tags.ByCount }}
{{ $v1 := where $tags "Count" ">=" 3 }}
{{ range $v1 }}
{{ end }}

This works fine when I use a regular partial passing through the page context, like {{ partial "tags.html" . }}

But when I try to pass through variables using dict, like this:

{{ partial "tags.html" (dict "context" . "tagCount" "3") }}

I get an error:

error calling partial: template: partials/tags.html:3:10: executing "partials/tags.html" at <where $tags "Count" ...>: error calling where: can't iterate over <nil>

As you can see, I don’t even know where to use context. but this is what I’m trying accomplish and haven’t gotten to yet: to change the “Count” in the $v1 v where statement from where I’m calling the partial.

  • A partial takes 1 “context” argument
  • So to pass more than one, you have to wrap it in a map (hence the dict func)
  • But then, when you do $.Site… that will not work because “$.” now references the map and not the page etc.
  • So .context.Site… would work

Okay. That’s pretty fundamental and what I was puzzled about. Thanks!