Created
June 24, 2022 21:50
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# 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