{
  "$type": "site.standard.document",
  "canonicalUrl": "https://www.simoncox.com/short-articles/2024-03-17-11ty-collection-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.",
  "path": "/short-articles/2024-03-17-11ty-collection-tag-links/",
  "publishedAt": "2024-03-17T12:40:20.056Z",
  "site": "at://did:plc:tki7vwlanxbwrz2er67eaeqa/site.standard.publication/3mp4h4md7zv2y",
  "tags": "Eleventy",
  "textContent": "More of a reminder for myself next time Image need to do this!\n\nAdding a collection tag to a post as a link\nThere 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.\n\nFor 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.\n\nI started with this 11ty code:\n\n~\n{% raw %}{% if tag == \"Modelling\" %}| <a href=\"/narrow-gauge-modelling\">Modelling</a>{% endif %}\n{% if tag == \"Loxley\" %}| <a href=\"/loxleybarton\">Loxley Barton Falls</a>{% endif %} {% endraw %}\n\n\nBut it wasn't showing up the tag links.\nTurns out that because I have multiple tags on some in this form:\n\n\ntags:\n- Loxley\n- Modelling\n\n\nTurns 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.\n\nThis gave me:\n\n\n{% raw %}{% for tag in tags %} \n  {% if tag == \"Modelling\" %}| <a href=\"/narrow-gauge-modelling\">Modelling</a>{% endif %}\n  {% if tag == \"Loxley\" %}| <a href=\"/loxleybarton\">Loxley Barton Falls</a>{% endif %}\n{%- endfor %}{%endraw %}\n~\n\nWhich works perfectly. I am sure there is a more robust method but for now, for me, this is working great!",
  "title": "11ty collections tag links"
}