runhide
October 22, 2017, 4:54pm
#1
As per the documentation, I’m using .Alphabetical.Reverse
to reverse the order of my taxonomy.
This is the code that works fine without .Alphabetical.Reverse
. It gives me the name of each category in alphabetical order.
{{range $name, $taxonomy := .Site.Taxonomies.categories}}
{{$name}}
{{end}}
When I add .Alphabetical.Reverse
, like so
{{range $name, $taxonomy := .Site.Taxonomies.categories.Alphabetical.Reverse}}
{{$name}}
{{end}}
I end up getting a list of numbers (0, 1, 2… 20) which I assume corresponds to each category. How can I convert these numbers to their names as before?
bep
October 22, 2017, 7:12pm
#2
Try:
{{range .Site.Taxonomies.categories.Alphabetical.Reverse}}
{{ .Title }}
{{end}}
runhide
October 22, 2017, 9:24pm
#3
Tried, but received the following error:
Error while rendering "home": template: index.html:25:13: executing "index.html" at <.Title>: can't evaluate field Title in type hugolib.OrderedTaxonomyEntry
bep
October 22, 2017, 9:32pm
#4
OK; my memory did not serve me well.
{{range .Site.Taxonomies.categories.Alphabetical.Reverse}}
Taxonomy: {{ .Name }}
{{ range .WeightedPages }}
Page: {{ .Title }}
{{ end }}
{{end}}
1 Like
runhide
October 22, 2017, 9:34pm
#5
That works beautifully. Thank you