I am getting this depreciation messages.

Looping through element queries directly has been deprecated. Use the all() function to fetch the query results before looping over them.

In the example below, the depreciation message refers to the 2nd loop for flag in country. The message appears anytime I have a loop within a loop.

How do I template this to avoid the deprecation message?

{% set entries = craft.entries.section('posts').all() %}

{% for first in entries[0:1] %}

{% set country = first.countryName %}

{% for flag in country %} 
<span class="flag-icon flag-icon-{{ flag.countryCode }}"></span>
{% endfor %}

<span>{{ first.title }}</span>

 {% endfor %}

1 Answer 1


What about using the all() function as well? Your field doesn't contain an array, it contains the same type of object like craft.entries provides.

{% for flag in country.all() %}

It doesn't appear because you have a loop in a loop it appears because you treat and object as an array

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.