HUGO

Where confusion

Can someone please explain why this works:

	{{ range .Site.Taxonomies.categories.aws }}
	<li>xx <a href="{{ .RelPermalink }}">{{ .Title }}</a></li>&nbsp;
	{{ end }}

but this doesn’t:

	{{ range where .Site.Taxonomies "categories" "aws" }}
	<li>xx <a href="{{ .RelPermalink }}">{{ .Title }}</a></li>&nbsp;
	{{ end }}

Sorry, I just can’t seem to figure it out! I am running Hugo v0.62.2

Hi there,

where filters an array: https://gohugo.io/functions/where/

.Site.Taxonomies is not an array.

2 Likes

@pointyfar is correct, but let’s get nerdy.

.Site.Taxonomies is a map of type hugolib.TaxonomyList. Map keys are referenced by the dotted notation in your first example.

So, to walk down the trail of your example in the Go codebase…

hugolib.TaxonomyList is of type map[string]Taxonomy. categories is the key in your example.

hugolib.Taxonomy is of type map[string]page.WeightedPages. aws is the key for all weighted pages with the aws category.

page.WeightedPages is of type []page.WeightedPage, which is a slice (an array, loosely speaking). If you wanted to filter pages by other front matter values, you could do it at this point.

You can see some of this by browsing the Godocs, but many things are hidden behind interface{} types so it’s hard to tell what’s going on sometimes without looking at the code.

3 Likes