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.

  • Hey can you give the full code for this. I tried on my end I can run loop.last without error.
    – aodihis
    Commented Sep 6, 2022 at 5:49

1 Answer 1


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

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.