I have 3 groups of tags that redirect to the same template. tags/index.html
. All the routing and linking those tags to their group page works well.
<a href="{{ siteUrl }}taggroup/{{ tag.slug }}"
The problem I have is that when I try to enter a tag that doesn't exist on the address bar (e.g., http://sitename/taggroup/unknowntag) I get all entries displayed.
Here's my tags/index.html
code:
{% if not tag %}
{% exit 404 %}
{% endif %}
{% set tag = craft.tags.slug(tag).first %}
{% set entries = craft.entries.relatedTo(tag).order('title').limit(null) %}
{% if entries | length %}
{% for entry in entries %}
<!-- Code Here -->
{% endfor %}
{% else %}
<!-- No Tag Code Here -->
{% endif %}
What Am I doing wrong? Thanks in advance.