I am trying to eager load an image asset assigned to a matrix. The template is pulling entries in from a section and each entry has the matrix field assigned to it that serves as an image gallery.
The error I am getting back using the syntax below is Craft\EntryModel and its behaviors do not have a method or closure named "primaryImage".
Section Handle: products
Matrix Field Handle: gallery
Block Type Handle: productImages
Field Handle: primaryImage, Field Type: Assets
{% set products = craft.entries({
section: 'products',
with:[
['gallery.productImages:primaryImage', {
withTransforms: [
'heroImage'
]
}],
]
}) %}
Template Code:
{% for entry in products %}
{% for block in entry.gallery %}
{% if block.type == 'productImages' %}
{% set img = entry.primaryImage[0] ?? null %}
{% if img %}
<img src="{{ img.url('heroImage') }}">
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
primaryImage
asset field definitely in the products section field layout?