0

I'm tried to following the how-to implement tags but can't see to get it to work. The how-to: https://craftcms.com/support/tag-urls

I created a new route, and in the URI field, I entered:

tags/( ‘tag’ token )

In the template field I entered:

tags/_tag

I created a folder in my template folder called tags and placed the template html file called:

_tags.html

_tags.html contains the following:

{% extends "_layout" %}
{% block content %}
    {% set tag = craft.tags.title(tag).first() %}

    <h1>Entries tagged with "{{ tag.title }}"</h1>

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

{% if entries | length %}
    <ul>
        {% for entry in entries %}
            <li>{{ entry.getLink() }}</li>
        {% endfor %}
    </ul>
{% else %}
    <p>No entries could be found with that tag.</p>
{% endif %} 
{% endblock %}

In my entry template, at the bottom, I have this snippet to list all related tags and to hyperlink those tags.

{% if entry.tags | length %}
    <h4>Tags</h4>
    <ul>
    {% for tag in entry.tags %}
        <li><a href="{{ siteUrl }}tags/{{ tag.title | url_encode }}" title="{{ tag.title }}">{{ tag.title }}</a></li>
    {% endfor %}
    </ul>
{% endif %}

An example of my entry is located below. It correctly shows the tag called 'Platformer' http://www.colorcomputergames.com/games/donkey-king

The URL, looks good. http://www.colorcomputergames.com/tags/Platformer

But when I go to the url, I get a 404

Cheers

5

You told Craft to look for tags/_tag

And then you created templates/tags/_tags.html

Note you have no s on the end in the route definition, but you do in the template name.

  • Oops, that was a typo. The route is tags/( ‘tag’ token ) and tags/_tags. The template file is tags.html. But not working. Still get a 404. – DevServe Dec 23 '16 at 0:31
  • BTW, I am following this tutorial: craftcms.com/support/tag-urls – DevServe Dec 23 '16 at 1:19
  • 1
    Ok next guess - did you actually use the tag token (from the UI list of available tokens), or did you actually type or copy tags/( ‘tag’ token ) – Jeremy Daalder Dec 24 '16 at 0:30
  • Uhg! Yeah, I copied and pasted tags/( ‘tag’ token )!! That's an easy mistake for a newbie!!I changed it to: tags/* I figure that means anything that starts with tags/ and any text after the / to route. Last thing to fix is {{ tag.title }}, as it isn't displaying. Also, it is showing ALL games with a tag, rather than JUST the game (entries) that use the tag. (See link in original post) – DevServe Dec 24 '16 at 6:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.