I searched the official documentation (which is constantly being improved) and the forum. But I haven’t found very clear answers to my questions.
Today, I feel like an idiot who doesn’t understand anything about Hugo.
I have 2 taxonomies declared in the configuration:
[taxonomies]
geo = "geo" # no plural, it's a choice
theme = "themes"
And in my pages:
geo = ["france", "germany", "switzerland"]
themes = ["cinema", "hugo", "music"]
I’m looking to do 3 separate things that are causing me problems.
On a content page (kind = page)
I’d like to list taxonomies and terms, but not do things like that:
{{ $taxonomyObject := .Site.Taxonomies.geo }}
<p>Geo: {{ range $taxonomyObject}} ... {{ end }}</p>
I’d like the taxonomy to be displayed if and only if it’s used on the page, then list the terms. In pseudo code:
range pageTaxonomies:
print TaxonomyTitle
range Terms:
print Term
So when I’m on a paris page, I’d like to see:
geo:
- france
themes:
- cinema
- music
On a taxonomy page (kind = taxonomy)
I’d like to list the site’s other taxonomies as related.
For the moment, I’m listing the terms in the taxonomy, classic usage.
{{ with .Pages}}
<ul>
{{ range . }}
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
{{ end }}
</ul>
{{ end }}
Below, I’d like a “see also”: list of other taxonomies on the site.
So when I’m on geo, I’d like to see:
geo:
- france
- germany
- swizerland
see also:
- themes
I think that depending on the variables that exist in Hugo, I need to go through site.Taxonomies
and remove the current one with an if eq...
. Right? Or is there another way of doing this?
I have an answer:
<ul>
{{ range (where site.AllPages "Kind" "taxonomy") }}
{{ if ne .Page page }}
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
{{ end }}
{{ end}}
</ul>
On a term page (type = term)
Below the list (similar to the code above), I’d like to see the other terms.
So when I’m on france, I’d like to see:
france:
- marseille
- paris
- [my pages]
see also:
- germany
- switzerland
It’s for this part of see also that I have no idea how to go about it. I know I missed something, but I’m still wondering what it is…
I have an answer (taxonomy is a parent of terms!):
{{ with .Parent }}
<ul>
{{ range .Pages }}
{{ if ne .Page page }}
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
{{ end }}
{{ end}}
</ul>
{{ end }}
Thank you in advance for giving me some clues to help me feel less stupid.