HUGO

[solved] Delimited complete list of taxonomy terms? (map to array?)

Currently I’m using CSS solution. It doesn’t work well for me and I want to replace it.

For page tags/categories there is nice solution available.
But it can’t be used for the full list of tags/categories.
.Site.Taxonomies.categories is a map, and apply can’t be used with maps.

  • Adding mapKeys, mapValues functions would be the cleanest solution.
  • Making apply function to work with maps in some way might also work.
  • range $index, $key, $value := $map might make it possible to use another solution.

Is there a sane way to achieve the same result in the current state of things?

Solved.
Alphabetical and ByCount return arrays.
And dict is used to pass taxonomy plural name into partial, in order to abstract over taxonomy.

    {{ $ty := "categories" }}
    {{ $terms := index .Site.Taxonomies $ty }}
    {{ with $terms.ByCount }}
      {{ $dicts := apply . "dict" "term" "." "taxonomy" $ty }}
      {{ $links := apply $dicts "partial" "link/term" "." }}
      {{ $clean := apply $links "chomp" "." }}
      {{ delimit $clean ", " }}
    {{ end }}

partials/link/term.html contents:

    <a href="/{{ .taxonomy }}/{{ .term.Name | urlize }}/">{{ .term.Name }}</a>