<p>You do not have to change your route. Instead modify your template where you are linking the tag.</p>

<p>Instead of using</p>

<pre><code>&lt;a href="{{ siteUrl }}tags/{{ tag.title | url_encode }}"&gt;{{ tag.title }}, &lt;/a&gt;
</code></pre>

<p>Use</p>

<pre><code>&lt;a href="{{ siteUrl }}tags/{{ tag.slug }}"&gt;{{ tag.title }}, &lt;/a&gt;
</code></pre>

<p><strong>UPDATED</strong></p>

<p>To clarify the above snippet goes in the template that generates the link to take the the user to your <code>_tag.html</code> template, not in the <code>_tag.html</code> template itself.</p>

<p>Your route should be as below:</p>

<p><a href="https://i.sstatic.net/I5yVA.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/I5yVA.png" alt="enter image description here"></a></p>

<p><strong>UPDATE 2</strong></p>

<p>Above snippet updated to match your example above.</p>

<p><strong>UPDATE 3</strong></p>

<p>As the <code>tag</code> variable made available to your template is now the tag’s slug, make sure to update the code to query for the tag model to use the <code>slug</code> param.</p>

<pre><code>{% set tag = craft.tags.slug(tag).first() %}
</code></pre>

CC BY-SA 3.0
2016-09-28T14:10:01.840Z
I get a 404 error when I do that
Andrew Staroscik
CC BY-SA 3.0
2016-09-28T14:22:18.320Z
The above snippet goes in the template that creates the link to your tag not in your _tag.html template
Fyrebase
CC BY-SA 3.0
2016-09-28T14:41:30.423Z
I've added more code to the question. Sorry for the lack of clarity. For the route, I am not typing (tag token) I am using the token option provided by the edit route dialogue box. If I type /tags/tag_token in the URI I get 404
Andrew Staroscik
CC BY-SA 3.0
2016-09-28T14:48:36.750Z
`tag_token` is not meant to be typed, it is a representation of the token option you are using. I added an image instead to clarify.
Fyrebase
CC BY-SA 3.0
2016-09-28T14:52:19.797Z
Yep that is exactly what I have
Andrew Staroscik
CC BY-SA 3.0
2016-09-28T14:59:45.630Z
Sorry, I'm not sure what else to suggest. I am using `{{ tag.slug }}` with success on multiple sites at present
Fyrebase
CC BY-SA 3.0
2016-09-28T15:03:46.597Z
Thank you. It does seem like it should work. Hopefully someone else can weigh in.
Andrew Staroscik
CC BY-SA 3.0
2016-09-29T07:30:02.550Z
@AndrewStaroscik I just updated the answer to add the changes to the criteria model we talked about in Craft Slack.
carlcs
CC BY-SA 3.0
2016-09-29T11:11:03.923Z
Nice catch @carlcs
Fyrebase
CC BY-SA 3.0
2016-09-28T14:06:58.687Z
2016-09-29T07:27:16.477Z
2016-09-29T07:27:16.477Z
Fyrebase
<p>I've followed <a href="https://craftcms.com/support/tag-urls" rel="nofollow">this guide</a> for creating a routes to list entries with specific tags. It is working fine except that I have muli-word tags so using the tag token from <code>Settings -&gt; Routes</code> gives me urls like </p>

<p><code>mysite.com/tags/my%20tag%20name</code></p>

<p>I'd like to us the tag.slug instead which should allow me to have urls end in <code>.../my-tag-name</code> instead, but I can't figure out how to do it. </p>

<p>Is there a way to refer to tag.slug in craft/config/routes.php?</p>

<p>If so what should the custom route look like:</p>

<p><code>'tags/what goes here?' =&gt; 'tags/_tag.html',</code></p>

<p><strong>Updated</strong></p>

<p>The template code is: </p>

<pre><code>{% extends "_layout" %}


{% block content %}

{% set tag = craft.tags.title(tag).first() %}

{% if not tag %}
    {% exit 404 %}
{% endif %}

&lt;h2&gt;Entries tagged with “{{ tag.title }}”&lt;/h2&gt;

{% set entries = craft.entries.relatedTo(tag).order('title') %}

{% if entries | length %}

        {% for entry in entries %}
            {{ include('./partials/entryListItem.html', {'entry': entry}) }}
        {% endfor %}
{% else %}
    &lt;p&gt;No entries could be found with that tag.&lt;/p&gt;
{% endif %}

{% endblock %}
</code></pre>

<p>and the include points to:</p>

<pre><code>&lt;div class='entry-list-item'&gt;
        &lt;h2&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/h2&gt;
        &lt;p&gt;
          &lt;a href="{{ entry.url }}"&gt;
            &lt;span class="sm-txt"&gt; continue reading&lt;/span&gt;
          &lt;/a&gt;
        &lt;/p&gt;
        {% if entry.tags | length %}
          &lt;p class='sm-txt'&gt;
          {% for tag in entry.tags %}
            &lt;a href="{{ siteUrl }}tags/{{ tag.title | url_encode }}"&gt;{{ tag.title }}, &lt;/a&gt;
          {% endfor %}
          &lt;/p&gt;
        {% endif %}
      &lt;/div&gt;
</code></pre>

<p>The route is set in the dashboard <code>tags/(tag token)</code> points to tags/_tag.html</p>

<p>If I change the route to <code>tags/(slug token)</code> I get template error: variable tag does not exist.</p>

CC BY-SA 3.0
2016-09-28T14:11:27.923Z
Can you provide the code you are using in your template and also what your route looks like?
Fyrebase
<routes><tags>
Use of tag.slug instead of tag.title in a custom route
# Use of tag.slug instead of tag.title in a custom route

(Asked by: username_0 on 2016-09-28)

I've followed this guide for creating a routes to list entries with specific tags. It is working fine except that I have muli-word tags so using the tag token from Settings -> Routes gives me urls like 
mysite.com/tags/my%20tag%20name
I'd like to us the tag.slug instead which should allow me to have urls end in .../my-tag-name instead, but I can't figure out how to do it. 
Is there a way to refer to tag.slug in craft/config/routes.php?
If so what should the custom route look like:
'tags/what goes here?' => 'tags/_tag.html',
Updated
The template code is: 
{% extends "_layout" %}


{% block content %}

{% set tag = craft.tags.title(tag).first() %}

{% if not tag %}
    {% exit 404 %}
{% endif %}

Entries tagged with “{{ tag.title }}”

{% set entries = craft.entries.relatedTo(tag).order('title') %}

{% if entries | length %}

        {% for entry in entries %}
            {{ include('./partials/entryListItem.html', {'entry': entry}) }}
        {% endfor %}
{% else %}
    No entries could be found with that tag.
{% endif %}

{% endblock %}

and the include points to:

        {{ entry.title }}
        
          
             continue reading
          
        
        {% if entry.tags | length %}
          
          {% for tag in entry.tags %}
            {{ tag.title }}, 
          {% endfor %}
          
        {% endif %}
      

The route is set in the dashboard tags/(tag token) points to tags/_tag.html
If I change the route to tags/(slug token) I get template error: variable tag does not exist.

**Tags:** routes, tags

> **Comments:**
> **username_1**: Can you provide the code you are using in your template and also what your route looks like?  

---

## 1 answers

### Answer by username_1 on 2016-09-28. Score: 3 | Accepted answer

You do not have to change your route. Instead modify your template where you are linking the tag.
Instead of using
{{ tag.title }}, 

Use
{{ tag.title }}, 

UPDATED
To clarify the above snippet goes in the template that generates the link to take the the user to your _tag.html template, not in the _tag.html template itself.
Your route should be as below:

UPDATE 2
Above snippet updated to match your example above.
UPDATE 3
As the tag variable made available to your template is now the tag’s slug, make sure to update the code to query for the tag model to use the slug param.
{% set tag = craft.tags.slug(tag).first() %}

> **Comments:**
> **username_0**: I get a 404 error when I do that  
> **username_1**: The above snippet goes in the template that creates the link to your tag not in your _tag.html template  
> **username_0**: I've added more code to the question. Sorry for the lack of clarity. For the route, I am not typing (tag token) I am using the token option provided by the edit route dialogue box. If I type /tags/tag_token in the URI I get 404  
> **username_1**: `tag_token` is not meant to be typed, it is a representation of the token option you are using. I added an image instead to clarify.  
> **username_0**: Yep that is exactly what I have  
> **username_1**: Sorry, I'm not sure what else to suggest. I am using `{{ tag.slug }}` with success on multiple sites at present  
> **username_0**: Thank you. It does seem like it should work. Hopefully someone else can weigh in.  
> **username_2**: @AndrewStaroscik I just updated the answer to add the changes to the criteria model we talked about in Craft Slack.  
> **username_1**: Nice catch @username_2  

---

