2

So i added a route to a template that shows entries by entry types. the way the template does it is by taking the last segment of the url, and using it as an entry slug for this filter: craft.entries.type(craft.request.getSegment(3)).relatedTo(category) So, how can i check if the string in the segment matches any of the entry types in that section, and if not - redirect to 404 page?

3

Take a look at the {% exit %} tag. You should be able to do something very similar, since your search will return no results if the entry type does not exist.

{% set entries = craft.entries.type(craft.request.getSegment(3)).relatedTo(category) %}

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

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.