Skip to content

Instantly share code, notes, and snippets.

@toddprouty
Created June 24, 2022 21:50
Show Gist options
  • Save toddprouty/03ec7c622848b1d129f76e7f6bbd48ae to your computer and use it in GitHub Desktop.
Save toddprouty/03ec7c622848b1d129f76e7f6bbd48ae to your computer and use it in GitHub Desktop.
Craft CMS: How to eager-load images and transforms nested in a Matrix field
{# eagerLoadElements() explained here: https://bit.ly/3taeKAV
TL;DR: eagerLoadElements() lets you use eager-loading syntax for stuff that’s tied
to entry already (i.e. stuff you don’t need to pull in via a query). #}
{% do craft.app.elements.eagerLoadElements(
className(entry),
[entry],
[
'heroImage',
['videoGrid.video:posterImage', {
withTransforms: ['wide1920', 'wide1280', 'wide768', 'wide640', 'wide384']
}]
]
) %}
{# videoGrid: matrix field
video: matrix block
posterImage: asset field in the video block #}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment