This question is a summary of my working with tags yesterday, I'm posting my findings to SE so other people can benefit.
For the purposes of this question, I'm going to be using a tag with the title 'Two Words'.
I'm trying to add a tags listing and filtering system to a blog. As tags don't have a 'slug' property, I've been having issues using them in URLs. If I use the following links:
{% for tag in tags %}
<a href="/news/tags/{{ tag.title }}">{{ tag.title }}</a>
{% endfor %}
Then you get unfriendly urls such as http://craft.dev/news/tags/Two%20Words
. If I use :
{% set tag = craft.tags.search(craft.request.getSegment(3)) %}
{% for entry in craft.entries.relatedTo(tag) %}
Then I get a list of articles that may contain the term "two words", but aren't actually tagged with Two Words
.
I want to list articles related to the tag in the URL, so how can I pull the specific tag from the url, making sure it stays 'url-friendly'?