Displaying Colour & Label coded Categories

Hi there,
On my list.html partial, I would like to display my category links with different colors.
For instance, on the blog post summary, I want to “General” category to be in blue background, and the “Tips” category to in purple background.
I have tested this method but returns a Hugo server error.
Not sure what’s wrong with this code, looks clean to me. Is it missing something?
{{ range $tag := .Params.tags }}
{{ if eq tag "hugo" }} <span class="tag" style="background-color: {{ .Site.Params.hugo }};">{{ $tag }}
{{ else if eq tag "gatsby" }} <span class="tag" style="background-color: {{ .Site.Params.gatsby }};">{{ $tag }}
{{ else }}
{{ $tag }}
{{ end }}

Code found here: https://rajasimon.io/hugo-colour-tags/
best result example is like using Trello with colour coded categories: https://blog.trello.com/hs-fs/hubfs/product%20management%20board.png?width=1600&name=product%20management%20board.png

Several problems:

  1. The code you posted is different than what appears on rajasimon.io. Look closely to see if you can find the differences.
  2. The code on rajasimon.io is missing a final {{ end }}.

In the future, when posting to this forum, please be more specific. This:

returns a Hugo server error

is not helpful.

Additionally, when posting code, please use code fences. See:

Thanks jmooring,
Sorry about the code layout, I thought it worked in the edit box, but when I published it, it was not. Thanks for the link, I will remember for next time.
I can’t see the difference, yet, but I’ll give it an other try.
About the error, it was such a long error and didn’t have any number. It was in redish background and specified the lines where the error was. It was highlighting the {{ end }} but every time I was deleting the line, the next previous one would be the error.
Hope this makes sense, but I’ll be working on it again.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.