0

When eager loading assets from within a matrix block like so:

{% set blocks = entry.relatedCategory
                     .with([categoryBlocks.blockType.blockAssetField])
                     .all() %}

What is the correct way of specifying that there are multiple block types to load that asset field from within?

Do you list each one manually:

{% set blocks = entry.relatedCategory
                     .with([
                            categoryBlocks.blockType.blockAssetField
                            categoryBlocks.blockTypeAlt.blockAssetField
                          ])
                     .all() %}

or is there a regex style version available, something like:

{% set blocks = entry.relatedCategory
                     .with([
                            categoryBlocks.{blockType|blockTypeAlt}.blockAssetField
                           ])
                     .all() %}

I have found that wildcarding works:

{% set blocks = entry.relatedCategory
                     .with([categoryBlocks.*.blockAssetField])
                     .all() %}

but this is only usable if all the block types contain the field.

I have read the docs, and looked over previous "eager-loading" tagged questions but not found anything on this.

Any clarification would be much appreciated

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.