R.T. Hinkel

Delimiting tags in HUGO

Dev

May 1, 2021


How to delimit tags in hugo and remove the trailing comma.

I was going a bit crazy and couldn’t figure this one out without getting into weird CSS territory and relying on janky :before styling.

Thankfully, there’s a post way towards the bottom of a HUGO discourse thread which seems to have gone a bit unloved.

I took this little bit of code:

10
11
12
13
14
15
16
17
18
19
20
21
{{- if .Params.tags -}} 
    {{- range $key, $tag := .Params.tags }} 
        {{- if ne $key 0 }}, {{ end }}
        <span>
          <a class="tags" href='/tags/{{ $tag | urlize }}'>
            {{ $tag }}
          </a>
        </span>
    {{- end -}}
    {{- else -}}
    None
{{- end -}}

And plugged it in to my existing post-tag list template.

Thanks denis77!


HUGO, Delimiting, Partials, No More Comma

Last modified: May 16, 2021


Related Posts


Comments