Hello - I wonder if someone more experienced could give me a hand. I’ve got a partial “listtop.html” which I use at the top of various lists, with the goal of having its contents show or hide depending upon the context.
One aspect of the partial is, I’d like to show a linked list of my taxonomy “topics”. This works:
{{ range $name, $taxonomy := .Site.Taxonomies.topics }}
<a href="/topics/{{ $name | urlize }}"> {{ $name }}</a>,
{{ end }}
… but it has a small irritation. The comma shows at the end of the list.
I therefore tried the technique described on this page in the docs, where a single post template is listing tag links, but removing the trailing comma with delimit
. To wit, my single has:
...
{{ partial "post/tag/list" . }}
...
Then layouts/partials/post/tag/list.html
is:
{{ with .Params.tags }}
<div class="tags-list">
<span class="dark-red">Tags</span><span class="decorative-marker">//</span>
{{ delimit (apply (apply (sort .) "partial" "post/tag/link" ".") "chomp" ".") ", " }}
</div>
{{ end }}
And the layouts/partials/post/tag/link.html
it’s calling is:
<a class="post-tag post-tag-{{ . | urlize }}" href="/tags/{{ . | urlize }}">{{ . }}</a>
This works fine for a single.html, and it serves up a clean list of linked tags, with no trailing comma. Now however, when I try this same technique for a taxonomy overall, I cannot seem to get it to work.
I tried:
{{ with Site.Taxonomies.topics }}
<div>
{{ $sort := sort . }}
{{ $links := apply $sort "partial" "topic_link" "." }}
{{ $clean := apply $links "chomp" "." }}
{{ delimit $clean ", " }}
</div>
{{ end }}
… calling layouts/partials/topic_link.html
:
<a href="/topics/{{ . | urlize }}">{{ . }}</a>
The above gives the error:
“ERROR: 2015/04/26 html/template: "partials/topic_list.html" is an incomplete template in partials/topic_list.html
”.
I tried variations, like with "Site.Taxonomies.topics"
to force a string, but in that case, I get an error related to sort.
It appears that taxonomies are a different animal, but I am not sure what kind of animal!
I wonder, can someone point me in the right direction? Thank you in advance.