11ty collections tag links
SimonCox
March 17, 2024
More of a reminder for myself next time Image need to do this!
Adding a collection tag to a post as a link
There are some lovely ways to automate sets of tags with a list page. Hoever I don't think these can have additional content to make them into a proper topic hub page so I am building them out manually.
For posts in my Articles and Shorts sections I have started adding tags to the modelling topic ones. After the author sign off with date, and update date if there is one, I have added links to the tag hub page.
I started with this 11ty code:
~
{% raw %}{% if tag == "Modelling" %}| Modelling{% endif %}
{% if tag == "Loxley" %}| Loxley Barton Falls{% endif %} {% endraw %}
But it wasn't showing up the tag links.
Turns out that because I have multiple tags on some in this form:
tags:
- Loxley
- Modelling
Turns out that 11ty concatenates them as a string, of course, so I need to cycle through that and pull out the tags that I need.
This gave me:
{% raw %}{% for tag in tags %}
{% if tag == "Modelling" %}| Modelling{% endif %}
{% if tag == "Loxley" %}| Loxley Barton Falls{% endif %}
{%- endfor %}{%endraw %}
~
Which works perfectly. I am sure there is a more robust method but for now, for me, this is working great!
Discussion in the ATmosphere