Is it possible to output a getSegments() array in a template to then run conditions on?

I can output one segment fine using getSegment(), but if I try to select one or more segments using getSegments() it outputs 'Array'.

Thanks in advance for any help.

1 Answer 1


That's because getSegments() returns an array. You can either get one of those segments by using:

{% set segments = craft.request.getSegments() %}
{{ segments[0] }}

Or loop through all returned segments:

{% for segment in craft.request.getSegments() %}
    {{ segment }}
{% endfor %}

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.