I’m not familiar with Hugo data model and can’t find a working detailed tutorial (or just example site) on using additional taxonomies metadata in templates. That’s why question is probably silly.
Regular page front matter:
authors: "william-thackeray"
/content/authors/william-thackeray/_index.md
fullname: "William Makepeace Thackeray"
list.html
<div class="meta-name">
{{ $tagsLen := len .Params.authors }}
{{ if gt $tagsLen 0 }}
{{ range .Params.authors }}
{{ . }}
{{ end }}
{{ end }}
</div>
as expected I see william-thackeray
The question is: what should be instead of dot (.) to output author’s fullname?
It works. Thank you! So specific taxonomy metadata access performed via Page object with special name %taxonomy_plural%/%term%
The only tip I’ve already bumped up is that front matter in yaml
---
authors: "william-thackeray"
---
leads to error “can’t iterate”. To access range iterations it’s necessary to write in list form even with single author:
Although I’m not sure that using “%s” to format an author’s full name will result in a valid URL here. E.g. “William Makepeace Thackeray” would result in
There’s nothing special about the name. It’s just the path to the page.
You should always specify taxonomy terms in a slice, even if there is only one.
Good, but there’s a simpler, more defensive way to iterate through the authors. Your empty slice check will throw an error if the page doesn’t contain authors in front matter. You don’t need to check for an empty slice—the range command does that for you.
<div class="meta-name">
{{ range .Params.authors }}
{{ (site.GetPage (printf "authors/%s" .)).Params.fullname }}
{{ end }}
</div>
Yes, you’re right. And even quotes are not necessary with this type of front matter. But some books must be with non-ASCII letters (yes, I know, removePathAccents=true) including cyrillic authors, titles and publishers. It’s not convenient to process and send urls like authors/лев-толстой. Hugo AFAIK still has no tools to make cyrillic transliterations like authors/lev-tolstoi and transparently work with them. So, after rigorous brainstorming I decided to use transliterated URLs as taxonomies with metadata.
Once more - thank you for detailed answers. They really not only helping realise my current humble project, but makes me better understand real power of Hugo.