This is a partial (array_to_sentence_string) that I translated from some code in Jekyll.
{{ $len := len . }}{{ if eq $len 1 }}{{ index . 0 }}{{ else if eq $len 2 }}{{ index . 0 }} and {{ index . 1 }}{{ else }}{{ $last := sub $len 1 }}{{ range first $last . }}{{ . }}, {{ end }}and {{ index . $last }}.{{ end }}
You use it as {{% array_to_sentence_string .Params.tags %}}. This results in:
item1, item2, and item3.
I also have partials/post/tag/list.html (in cabaret) that more closely does what you want.
{{ with .Params.tags }}
<div class="tags-list">
<span class="dark-red">Tags</span><span class="decorative-marker">//</span>
{{ $len := len . }}
{{ if eq $len 1 }}
{{ partial "post/tag/link" (index . 0) }}
{{ else }}
{{ $last := sub $len 1 }}
{{ range first $last . }}
{{ partial "post/tag/link" . }},
{{ end }}
{{ partial "post/tag/link" (index . $last) }}
{{ end }}
</div>
{{ end }}
sort .Params.tags => sort [ c, a, b ] => [ a, b, c ]
Applies the function partial over the elements of $sort and assigns the resulting list to $links. The partial function is given post/tag/link as the name of the partial to use, and "." is the placeholder for the current element during function application.
Donāt you think there should be an easy way ? A function that would output directly a list of taxonomy and links. Maybe I should open a feature request for that.
Thanks anyway for taking the time to explain your method !