I’m trying to see if improving taxonomy term listing (from pages) would get any traction here. Particularly the adding of a new Site/Page method. I know this subject has been discussed before, but the following approach may be better suited and avoid code breaking.
In short, it would involve a new method on both .Site
and Page:
.Site.GetTerms "tags"
> returns all the terms of the taxonomy “tags” as page objects.
.GetTerms "tags"
> same as above but limited to the current page’s assigned terms.
Here’s why I think this feature is needed:
Currently there are two ways to list terms from outside the taxonomy landing page.
On the site level, retrieving all the terms:
.Site.Taxonomies.tags
returns an array of terms from which you can only get two informations per term:
- The term slug/id
- The pages belonging to the term
On the page level:
One must use .Params.tags
which will return a list of tags as added by the editor.
Both situation (site context and page context) leaves the coder in charge of building the proper permalink (and sometime name).
As per the doc:
<ul id="tags">
{{ range .Params.tags }}
<li><a href="{{ "/tags/" | relLangURL }}{{ . | urlize }}">{{ . }}</a> </li>
{{ end }}
</ul>
On the site level, you need to get the tag slug from the $index
.
If more information are needed from the term (dedicated Front Matter), coder must use .GetPage
on each of them.
With a dedicated method like .GetTerms
, listing terms on a page would be clearer and more error proof:
{{ with .GetTerms "tags" }}
{{ range . }}
<li>
{{ with .Params.icon }}
{{ <i class="{{ . }}"></i>
{{ end }}
<a href="{{ .Permalink }}">{{ .Name }}</a>
</li>
{{ end }}
{{ end }}
Adding a new method rather than changing something already in place avoids code breaking and limit the usage of the new feature to the people aware of it.
This is the thinking of me alone, so it this method and its one parameter may be flawed (or not needed by any one else but me). I’m merely trying to see if other people care join the conversation about the need for such a feature.