Hugo Logo

Nice to have a set of tags on your post, that are clickable and correctly comma delimited … meaning the last tag doesnt get a comma.

example:

tags: [tag1], [tag2], [tag3]

what we dont want

tags: [tag1], [tag2], [tag3],

Here’s the old code that worked with the extra comma after the last tag.

    <span class="inline-item"><a href="/tags/{{ . | urlize }}">{{ . }}</a>,</span>

Here’s the correct code - with a full stop at the end - remove it if you think it doesn’t fit your style.

    <span class="inline-item text-black tags">
    {{ range $key, $value := $.Params.tags }}
        <a href="/tags/{{ $value | urlize }}">{{ $value }}</a>{{ if ne $key (sub (len $.Params.tags) 1) }}, {{ else }}.{{ end }}
    {{ end }}
    </span>
Tags: Tags, Content Management, User Experience

Read more from my blog for an introduction and quick tips on developing in Hugo or UCTD.

Meet the author

Photo for Damien Saunders
Damien Saunders
An experienced management consultant and business leader interested in digital transformation, product centred design and scaled agile. If I'm not writing about living with UCTD (an autoimmune disease), I'm probably listening to music, reading a book or learning more about wine.
Find our more about me.