I currently have two taxonomies I’m managing on my site:
- tags
- categories
I loop over these in my layout to output a comma-separated list of terms for a post byline, e.g.
Published by Josh Habdas 9 Mar, 2017 in technology and design and tagged javascript, open source, programming and web development using 881 words.
When output, individuals terms are converted to hyperlinks using apply
with a partial:
{{ with .Params.categories }}
in <span itemprop="articleSection">{{ delimit (apply (apply (sort .) "partial" "post/category-link.html" ".") "chomp" ".") ", " " and " }}</span>
{{ end }}
{{ with .Params.tags }}
and tagged {{ delimit (apply (apply (sort .) "partial" "post/tag-link.html" ".") "chomp" ".") ", " " and " }}
{{ end }}
With the following partials used, shown here combined for brevity:
<a href="{{ "/" | relURL }}categories/{{ . | urlize }}/">{{ . }}</a>
<a href="{{ "/" | relURL }}tags/{{ . | urlize }}/">{{ . }}</a>
I’d ideally like to DRY up this code, but moreso I want to remove the hardcoding of the taxonomy name from within the partial URL, so I can control taxonomy names from config without forcing a refactor. Something like this:
<a href="{{ "/" | relURL }}{{ ($.Site.GetPage "taxonomy" "categories").Data.Plural }}/{{ . | urlize }}/">{{ . }}</a>
But when do I receive the following error:
ERROR: 2017/05/02 13:43:47 general.go:236: theme/partials/post/category-link.html is an incomplete or empty template
The same holds true anytime I try and access $.Site
from within a partial applied in this manner.
Assuming I’m doing something dumb (because I usually am), why does the above snippet throw an error? And what would be the suggested approach to handle this scenario for the purposes of a translated site without altering the way with which I’m outputting the byline?