I am trying to check if a value provided by the user (url segment) matches an entry type, and if not redirect to 404.

{% set section = craft.sections.getSectionByHandle('shop') %}
{% set entryTypes = section.getEntryTypes('handle') %}
{% if not segmentEntryType in entryTypes|keys %}
    {% exit 404 %}
{% endif %}

segmentEntryType is the string from the segment. i get the error:

An exception has been thrown during the compilation of a template ("Node "1" does not exist for Node "Twig_Node".").
  • You need to specify what the entry type are (unless you are getting the entry type "handle")
    – Martin
    Commented Aug 6, 2015 at 12:31
  • How can i get a list of the entry type's handels?
    – Samuel E.
    Commented Aug 6, 2015 at 12:37
  • If you go to settings->sections, that will show a list of all section and their handles. if you then click on edit entry type for a section (a channel section) it should give you a list of entry types and their handles.
    – Martin
    Commented Aug 6, 2015 at 12:42
  • No, what i mean is that how can i put a list of the existing entry type's handles so i can check if segmentEntryType matches one of them, and if it desn't redirect to 404 page. thats what i'm trying to do.
    – Samuel E.
    Commented Aug 6, 2015 at 12:48
  • {% set entryTypes = section.getEntryTypes() %} should return an array of entryTypes
    – Martin
    Commented Aug 6, 2015 at 12:58


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.