I am curious coz I am looking for a way to define via .Param which terms can show up and a default term to fall back on. For example, I would like to do get_terms = ['tags'] or get_terms = ['tags','categories'] and then do .GetTerms ($.Param "get_terms").
I am also open to more ideas to configure such a thing.
You would need an outer loop to range through the taxonomies, and an inner loop to range through the terms returns by .GetTerms, discarding those you don’t want.
git clone --single-branch -b hugo-forum-topic-56095 https://github.com/jmooring/hugo-testing hugo-forum-topic-56095
cd hugo-forum-topic-56095
hugo server
Files of interest:
hugo.toml
layouts/_partials/terms.html
The partial does two things:
Builds a data structure of the terms assigned to the current page, grouped by taxonomy, excluding terms in the “exclude list” as defined in front matter (if any), falling back to the “exclude list” as defined in the site configuration (if any). Invert the logic if you’d rather use an “include list”.
Renders the data structure as a nested, unordered list.
Default terms are assigned by cascading from the site configuration.
Hi Joe. I made a mistake when I said “terms”. What I really meant is this.
./config/default/params.toml
[list]
get_ terms = [''] # e.g ['tags'], ['categories','tags'] etc. Could be any user defined taxonomy
[page]
get_ terms = [''] # e.g ['tags'], ['categories','tags'] etc. Could be any user defined taxonomy
So, when a taxonomy is added (or taxonomies are added) in such a way, then the terms from those taxonomies will show up. e.g
./layout/list.html
{{ with $.Param "list.get_terms" | default "categories" }}
<!--- Code for .GetTerms goes here. Preferably a reusable partial--->
{{ end }}
./layout/page.html
{{ with $.Param "page.get_terms" | default "categories"}}
<!--- Code for .GetTerms goes here. Preferably a reusable partial--->
{{ end }}
The reusable partial will then fetch the given terms for the defined taxonomies (array) and fall back to categories taxonomy terms if none are user defined.
Param here means it should be configurable per page or in params.
The use case is showing the defined taxonomy’s terms in each single page or in each page entry in the list page.
(Maybe get_terms should be get_taxonomy_terms.)
I hope that’s clear. Thanks in advance.
(The configuration is defined like [list] and [page] also coz styling is different, alongside configuring appearace for page and list pages.)