I have a Matrix field with a single block type and within that, a number of fields that I need to pull out:

{% for roomContent in hotelEntry.roomsAvailable %}
    {% if roomContent.code == room.roomTypeCode %}
        <p>room code = {{ roomContent.code }}<br>
            description = {{ roomContent.description }}<br>
            {% for image in roomContent.images %}
                <img src="{{ image.url }}" alt="{{ roomContent.description }}" height="50">
            {% endfor %}
    {% endif %}
{% endfor %}

I am doing this on a listing page where there are around 60 entries, so this is resulting in a lot of calls to the DB.

Is there a way I can eager load all of the data for all of the entries outside of this loop so I'm not recursively calling for data?

1 Answer 1


No you can't with any build in Craft functions. I've added a feature request for this on Crafts feedback site.

What you can do for now is to use Mike Peppers excellent Plugin "Fetch" which pre-fetch relations for you.

Ser here https://github.com/mdcpepper/fetch

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.