<p>Updated answer: make sure your for loop is calling <code>.all()</code> and <code>{{loop.last}}</code> should work.</p>
<p><strike>You'll need to use <code>{% if loop|last %}</code>. This has changed in Twig 3 (which i guess Craft 4 is now using).</p>
<p>See: <a href="https://twig.symfony.com/doc/3.x/filters/last.html" rel="noreferrer">https://twig.symfony.com/doc/3.x/filters/last.html</a></strike></p>

CC BY-SA 4.0
2022-09-08T20:02:39.247Z
2022-09-27T14:51:01.133Z
2022-09-27T14:51:01.133Z
alexr
<p>Craft 4</p>
<pre><code>Key &quot;last&quot; for array with keys &quot;parent, index0, index, first&quot; does not exist.
</code></pre>
<p>When using</p>
<pre><code>{% if loop.last %}
</code></pre>
<p>Data is there and printing out a menu but cannot seem to get the last loop.</p>

CC BY-SA 4.0
2022-09-06T05:49:04.670Z
Hey can you give the full code for this. I tried on my end I can run loop.last without error.
aodihis
<templating><loop>
Loop last error getting entries
# Loop last error getting entries

(Asked by: username_0 on 2022-09-05)

Craft 4
Key "last" for array with keys "parent, index0, index, first" does not exist.

When using
{% if loop.last %}

Data is there and printing out a menu but cannot seem to get the last loop.

**Tags:** templating, loop

> **Comments:**
> **username_1**: Hey can you give the full code for this. I tried on my end I can run loop.last without error.  

---

## 1 answers

### Answer by username_2 on 2022-09-08. Score: 14

Updated answer: make sure your for loop is calling `.all()` and `{{loop.last}}` should work.

You'll need to use `{% if loop|last %}`. This has changed in Twig 3 (which i guess Craft 4 is now using).

See: <https://twig.symfony.com/doc/3.x/filters/last.html>


---

