Get all unique taxonomies of a page

I was trying to get the tags of all the blog posts under /blog page. If you wanted to display these tags related to ONLY the blog on your page, maybe this could help you:

{{ $blog := .Site.GetPage "/blog"}}
{{ $slice := slice }}
{{ range $page := $blog.Data.Pages }}
    {{ range $tag := $page.Params.tags }}
        {{ $slice = $slice | append $tag }}
    {{ end }}
{{ end }}

{{ range $uniqueTags := $slice | uniq }}
    {{ $uniqueTags }} <br/>
{{ end }}

This should give out all the tags uniquely, same goes to categories or any other taxonomy (or params).


Thanks for sharing. This seems like it would be a great example to add to the documentation.

Yeah. Where do you think it would be nice to put in? Under Taxonomy or the slice function?

I was thinking taxonomy :smile:


1 Like