But I want to sort taxonomies, NOT pages inside them. I can sort pages inside taxonomies using ByWeight.
Also adding .WeightedPages after categories does not work
Thanks
{{ range $key, $taxonomy := .Site.Taxonomies.categories.WeightedPages }}
{{ range .Pages.ByWeight }}
{{ end }}
{{ end }}
I’m not sure it works, but I’d try assigning weight to the front matter of the taxonomy terms. If the built-in weight mechanism doesn’t work for terms, then you can always code it up in your partial.
You are searching in vain because you aren’t sharing your code/repo. Without seeing what you are doing, we are guessing. If you can’t share your site’s repo, please make a new one you can, and reproduce your issue. But once we can see what’s happening, someone will be able to tell you one way or another.
@ju52 Thanks for your reply
I added categories_weight: 2 at the frontmatter.
Nothing changes and I suppose nothing will change until I find how to retrieve this data to sort
at
{{ range $key, $taxonomy := .Site.Taxonomies.categories }}
@ju52categories_weight = 44 is for weighing a piece of content inside a taxonomy (categories in this case). The poster wants to weigh terms against each other.
If I try
{{ range sort $key, $taxonomy := .Site.Taxonomies.categories “weight” }}
then I get error
parse failed: template:: undefined variable “$key”
If
{{ range $key, $taxonomy := (sort .Site.Taxonomies.categories “.Params.weight”) }}
then
error calling sort: Params is neither a struct field, a method nor a map element of type page.WeightedPages
The answer to your question is in the post I linked to.
I did not copy that code block in its entirety because I thought you wanted a sorted taxonomy terms list, (I hadn’t read every post above).
In any case it’s certainly doable to render the list as you ask, like this:
{{ define "main"}}
{{ $taxo := "categories" }}
<ul>
{{ with ($.Site.GetPage (printf "/%s" $taxo)) }}
{{ range .Pages.ByWeight }}
<li><a href="{{ .RelPermalink }}">{{ .File.Dir | title }}</a>
<ul>
{{ range .Pages }}
<!-- this also lists the content pages associated with the term;
remove if not needed. -->
<li>{{ .Title }}</li>
{{ end }}
</ul>
</li>
{{ end }}
{{ end }}
</ul>
{{ end }}