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

<pre><code>{% set segments = craft.request.getSegments() %}
{{ segments[0] }}
</code></pre>

<p>Or loop through all returned segments:</p>

<pre><code>{% for segment in craft.request.getSegments() %}
    {{ segment }}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2015-10-12T10:39:47.000Z
2015-10-12T10:39:47.000Z
Paul
<p>Is it possible to output a <code>getSegments()</code> array in a template to then run conditions on?</p>

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

<p>Thanks in advance for any help.</p>

<templating><array><getsegment><output>
Output getSegments() array in template
# Output getSegments() array in template

(Asked by: username_0 on 2015-10-12)

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.

**Tags:** templating, array, getsegment, output

---

## 1 answers

### Answer by username_1 on 2015-10-12. Score: 1 | Accepted answer

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 %}


---

