Better term listing

Correct me if I’m wrong, but currently to best way to lists terms (as links) from a certain taxonomy associated to a post is this way:

{{ range .Params.locations }}
<a href="{{ "/locations/" }}{{ . | urlize }}">{{ . }}</a>
{{ end }}

or

{{ range .Params.locations }}
   {{ $term := $site.GetPage "taxonomy" "locations" (lower .) }}
   <a href="{{ $term.Permalink }}">{{ $term.Title }}</a>
{{ end }}

1/ Is there a better way I am not aware of?

2/ Wouldn’t it be possible to generate a list of term object complete with .Permalink and .Title available inside the .Page (.) context.
So we could use something like this from inside the .Page context

{{ range .Taxonomies.locations }}
   <a href="{{ .Permalink }}">{{ .Title }}</a>
{{ end }}

Hugo knows those Front Matter params are Taxonomies since they are declared in the config file. So it could differentiate the locations array from any other Front Matter array and serve them this way.

Is it very complicate or too heavy to implement?

2 Likes

I have a tag list with buttons - this is my list template:

{{ define "main" }}
	{{ "<!-- layout/tag/list.html -->" | safeHTML }}
	<article class="post">
	<h1><a rel="full-article" href="{{ .Permalink }}">{{ .Site.Title }} &middot; all tags</a></h1>
	<hr/>
	<div class="row"><span class="tags">
		{{range $name, $taxonomy := .Site.Taxonomies.tags}}
			<a class="tagbutton" href="{{ $.Site.BaseURL }}/tags/{{$name | urlize  | lower }}" title="">{{$name}}&nbsp;<sup>{{.Count}}</sup></a>
		{{ end }}
	</div>
	<hr/>
	</article>
{{ end }}