<p>It's <s>not documented</s>, but it looks like there's both, a <code>slug</code> property for tags and also a <code>slug</code> parameter for the <code>craft.tags</code> criteria model.</p>

<pre><code>{% set tagSlugs = 'one,two,three'|split(',') %}

{% set tags = craft.tags.slug(tagSlugs) %}

{% for tag in tags %}
    {{ tag.slug }}
{% endfor %}
</code></pre>

<p><strong>Update:</strong><br>
Both the <code>slug</code> property and the param are now mentioned in the Craft docs.</p>

CC BY-SA 3.0
2015-10-28T11:11:53.097Z
2017-05-05T19:57:43.143Z
2017-05-05T19:57:43.143Z
carlcs
<p>The key to this is to use the <code>|kebab</code> filter and the <code>relatedTo</code> params.</p>

<p><strong>Listing:</strong></p>

<pre><code>{% for tag in relatedTags %}
    &lt;li&gt;&lt;a href="/news/tags/{{ tag.title|kebab }}"&gt;{{ tag.title }}&lt;/a&gt;&lt;/li&gt;
{% endfor %}
</code></pre>

<p><strong>Fetch related articles</strong></p>

<pre><code>{% set tag = craft.tags.search(craft.request.getSegment(4)) %}

{% for entry in craft.entries.relatedTo({ targetElement: tag[0], field: tagField }) %}
</code></pre>

<p>The <code>tag[0]</code> is necessary, as <code>{{ craft.tags.search() }}</code> will return an array (even if there's only one tag returned).</p>

<p>This finds entries that are specifically related to <code>Two Words</code> (a tag object, pulled from the URL), and searches in the <code>tagField</code> specified.</p>

<p>The alternative to the above is to use <code>{{ tag.id }}</code> and <code>{{ craft.tags.id() }}</code>, but that isn't URL/SEO friendly.</p>

CC BY-SA 3.0
2015-06-25T10:35:23.900Z
2015-06-25T10:35:23.900Z
darylknight
<p><strong>This question is a summary of my working with tags yesterday, I'm posting my findings to SE so other people can benefit.</strong></p>

<hr>

<p>For the purposes of this question, I'm going to be using a tag with the title 'Two Words'.</p>

<p>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:</p>

<pre><code>{% for tag in tags %}
    &lt;a href="/news/tags/{{ tag.title }}"&gt;{{ tag.title }}&lt;/a&gt;
{% endfor %}
</code></pre>

<p>Then you get unfriendly urls such as <code>http://craft.dev/news/tags/Two%20Words</code>. If I use :</p>

<pre><code>{% set tag = craft.tags.search(craft.request.getSegment(3)) %}
{% for entry in craft.entries.relatedTo(tag) %}
</code></pre>

<p>Then I get a list of articles that may contain the term "two words", but aren't actually tagged with <code>Two Words</code>.</p>

<p>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'?</p>

<entries><relations><tags>
How can I use tag slugs in URLs?
# How can I use tag slugs in URLs?

(Asked by: username_0 on 2015-06-25)

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 %}
    {{ tag.title }}
{% 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'?

**Tags:** entries, relations, tags

---

## 2 answers

### Answer by username_0 on 2015-06-25. Score: 4 | Accepted answer

The key to this is to use the |kebab filter and the relatedTo params.
Listing:
{% for tag in relatedTags %}
    {{ tag.title }}
{% endfor %}

Fetch related articles
{% set tag = craft.tags.search(craft.request.getSegment(4)) %}

{% for entry in craft.entries.relatedTo({ targetElement: tag[0], field: tagField }) %}

The tag[0] is necessary, as {{ craft.tags.search() }} will return an array (even if there's only one tag returned).
This finds entries that are specifically related to Two Words (a tag object, pulled from the URL), and searches in the tagField specified.
The alternative to the above is to use {{ tag.id }} and {{ craft.tags.id() }}, but that isn't URL/SEO friendly.


---

### Answer by username_1 on 2015-10-28. Score: 1

It's not documented, but it looks like there's both, a slug property for tags and also a slug parameter for the craft.tags criteria model.
{% set tagSlugs = 'one,two,three'|split(',') %}

{% set tags = craft.tags.slug(tagSlugs) %}

{% for tag in tags %}
    {{ tag.slug }}
{% endfor %}

Update:
Both the slug property and the param are now mentioned in the Craft docs.


---

