<p>You need to execute the element query, then access the second element of the resulting array:</p>
<pre class="lang-twig prettyprint-override"><code>{% set secondImage = entry.images.all()[1].url ?? null %}
{% if secondImage %}
    {# … #}
{% endif %}
</code></pre>
<p>The null coalescing operator (<code>??</code>) is useful here to prevent errors in case there aren't two images selected in the <code>images</code> field.</p>

CC BY-SA 4.0
2023-03-14T16:27:14.527Z
Just need to replace `images().` by `images.`
Nikolay Bronskiy
CC BY-SA 4.0
2023-03-14T16:28:35.900Z
I can't edit it as stackexchange demand at least 6 changed characters :)
Nikolay Bronskiy
CC BY-SA 4.0
2023-03-14T16:28:36.160Z
@NikolayBronskiy Ah yes, good catch, slip of the pen :)
MoritzLost
CC BY-SA 4.0
2023-03-14T15:35:16.523Z
2023-03-14T16:28:12.830Z
2023-03-14T16:28:12.830Z
MoritzLost
<p>In craft cms 3 we could use this:</p>
<pre><code>{{ entry.images[1].url }}
</code></pre>
<p>But how can I get second asset in Craft CMS 4?</p>

<assets><craft4>
How to get second asset in Craft CMS 4?
# How to get second asset in Craft CMS 4?

(Asked by: username_0 on 2023-03-14)

In craft cms 3 we could use this:
{{ entry.images[1].url }}

But how can I get second asset in Craft CMS 4?

**Tags:** assets, craft4


---

## 1 answers

### Answer by username_1 on 2023-03-14. Score: 2 | Accepted answer

You need to execute the element query, then access the second element of the resulting array:
{% set secondImage = entry.images.all()[1].url ?? null %}
{% if secondImage %}
    {# … #}
{% endif %}

The null coalescing operator (??) is useful here to prevent errors in case there aren't two images selected in the images field.

> **Comments:**
> **username_0**: Just need to replace `images().` by `images.`  
> **username_0**: I can't edit it as stackexchange demand at least 6 changed characters :)  
> **username_1**: @NikolayBronskiy Ah yes, good catch, slip of the pen :)  

---

