Sorting after separating into key value

In the code below, how to sort the whole thing by {{ len $value }}

{{ range $name, $value := .Site.Taxonomies }}      
    <h4>{{ $name | humanize }} - {{ len $value }}</h4>
{{ end }}

I don’t know any built in ways of sorting it, but you could map the taxonomies to dicts and sort according to a dict key, like mentioned here.

It seems quite unusual to require this, though. Usually you’d want to sort within a specific taxonomy and put the terms (like specific tags) which have most matching pages on top (using .Data.Terms.ByCount within taxonomy page).
In case of needing hierarchical taxonomies I would try the trick mentioned in multi-level taxonomy topic.

1 Like