We've retired the forum in favor of GitHub Discussions.

New conversations can be started on GitHub. Existing conversations will remain for a while longer.

Head over to GitHub →

404 not working for taxonomies.html when tag doesn't exist

Brendan Falkowski September 11, 2014 by Brendan Falkowski

Follow-up from: http://support.statamic.com/discussions/problems/2017-404-not-working-for-taxonomieshtml-when-tag-doesnt-exist

If I visit a URL like: http://domain.com/blog/tags/tag-that-does-not-exist

Then the page does not 404 error.

In the taxonomies.html template though (for the Denali example theme) there seems to be a conditional to test if the slug exists, but this doesn't render.

{{ if taxonomy_slug }}
    ---show entries matching the tag---
{{ else }}
    {{ content }}
{{ endif }}

I'd probably prefer the 404, but I'd be fine with the conditional allowing me to return "The tag 'xyz' doesn't exist."

Answer from Gareth Redfern:

What that code is doing is looking to see if whatever keyword you set for your taxonomy is in the url not whether the tag exists if that makes sense? So in other words it looks at the following:

blog/tags/non-existing-tag-name because tags is in the url and is one of your taxonomy keywords it passes as true even though the tag doesn't exist. I am not sure if what you are trying to achieve is possible but the way I do things is just have a no results tag in my entries listing which will display no results see:



I will ask Jack and Fred though and see if it is possible a different way.

Reply from Brendan Falkowski:

Hmm, it seems like that {{ if taxonomy_slug }} would never be false because a URL like blog/labels/some-label-name triggers the 404 if "labels" was not a configured taxonomy. The 404 happens before the template renders the conditional.

Just tested this again with:

{{ if taxonomy_slug }}
    {{ if no_results }}
        This never renders.
    {{ else }}
        Shows entries with the tag.
    {{ endif }}
{{ else }}
    This never renders.
{{ endif }}

The {{ no results }} conditional doesn't render for a valid taxonomy and non-existing tag like: /blog/tags/non-existing-tag

Answered by Brendan Falkowski!
>>>>>>> Answered <<<<<<<
2 Replies
1 Follower