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 %}
<h2>Entries tagged with “{{ tag.title }}”</h2>
{% set entries = craft.entries.relatedTo(tag).order('title') %}
{% if entries | length %}
{% for entry in entries %}
{{ include('./partials/entryListItem.html', {'entry': entry}) }}
{% endfor %}
{% else %}
<p>No entries could be found with that tag.</p>
{% endif %}
{% endblock %}
and the include points to:
<div class='entry-list-item'>
<h2><a href="{{ entry.url }}">{{ entry.title }}</a></h2>
<p>
<a href="{{ entry.url }}">
<span class="sm-txt"> continue reading</span>
</a>
</p>
{% if entry.tags | length %}
<p class='sm-txt'>
{% for tag in entry.tags %}
<a href="{{ siteUrl }}tags/{{ tag.title | url_encode }}">{{ tag.title }}, </a>
{% endfor %}
</p>
{% endif %}
</div>
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.