List all tags, categories

I’m trying to list/loop through all tags used in an entire hugo site. I have taken some time, looking around I got this

{{ range .Site.Taxonomies.tags }}

That doesn’t get me very far though; I’m still outputing some spaghetti mess. It occurs to me that I’m missing something, that could probably be identified quickly. Any links (perhaps even to older questions here) or ideas?

You first: Requesting Help

Please share a repo, so folks can see what you are doing.

1 Like

my solution

	{{range $name, $taxonomy := .Site.Taxonomies.tags}} {{ $cnt := .Count }}
	  {{ with $.Site.GetPage (printf "/tags/%s" $name) }}
          <div class="tagbutton">
		<a href={{ .RelPermalink }} title="All pages with tag <i>{{$name}}</i>">{{$name}}</a>
		<sup>{{$cnt}}</sup>
          </div>
	  {{end}}
	{{end}}
5 Likes

@ju52, thanks a lot man. This worked like a charm. Just what I was looking for.

Very nice, this worked for me also! Thanks!
BTW, changing the reference to .tags > to .categories also listed the categories, so I guess the approach would work for any term! Thanks!

I suggest you read our great documentation on this, but it helps to remember that a taxonomy is just a Page (a branch node), so you can do similar to:

{{ $tags := site.GetPage "/tags" }}
{{ range $tags.Pages }}
 <a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
{{ end }}
2 Likes