Applying style to list.html template based on selected tag

Hi. I’m trying to apply a specific set of colors based on the tag to a list of posts.
Put a piece of code in the header checking whether the tag is present in the Params.tags and then based on that renders a subset of styles inside tags that come after the main stylesheet.

So far this is working for the single template, but the list template is not.
In this example, games:

{{ if in .Params.tags “games”}}
{{ partial “games_style.html” . }}
{{else}}
{{ partial “site_style.html” . }}
{{ end }}

Works fine when i enter a post that has the tags games but not the case when I enter the list with the url website.com/tags/games, the style used is the site_style.

I believe this is because the tags are checked by post and not in the whole list.

Is there any workaround for this?

Thanks!

Your code checks for .Params.tags, which are page variables. You’ll need to check for something else, such as term name (“games” in this case).

2 Likes

This worked. Thanks! (note the Capitalized term name).

{{ if in .Name “Games”}}
{{ partial “games_style.html” . }}
{{else}}
{{ partial “site_style.html” . }}
{{ end }}

1 Like