---
type: Article
title: 11ty collections tag links
description: Adding tag links to Eleventy posts for better topic navigation and solving an issue with multiple tags by iterating through them to create proper links.
resource: https://www.simoncox.com/short-articles/2024-03-17-11ty-collection-tag-links/
tags: [Shorticles, Eleventy]
timestamp: 2024-03-17
---

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" %}| <a href="/narrow-gauge-modelling">Modelling</a>{% endif %}
{% if tag == "Loxley" %}| <a href="/loxleybarton">Loxley Barton Falls</a>{% 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" %}| <a href="/narrow-gauge-modelling">Modelling</a>{% endif %}
  {% if tag == "Loxley" %}| <a href="/loxleybarton">Loxley Barton Falls</a>{% endif %}
{%- endfor %}{%endraw %}
~~~

Which works perfectly. I am sure there is a more robust method but for now, for me, this is working great!

[Read full article](https://www.simoncox.com/short-articles/2024-03-17-11ty-collection-tag-links/)
