I'm trying to loop through images that are eager-loaded inside matrix block, but I can't get the images inside a matrix field handle to loop and show each individual image.
The loop I have loops the correct amount of times (based on how many images there are in each matrix block), but it just shows the first image of the loop.
Here's the set up:
Section handle: products Matrix field handle: imageTextSections Block type handle: sectionBlock Field handle: sectionBlockImages Field type: Assets
I'm trying to loop through images that are eager-loaded inside matrix block, but I can't get the images inside a matrix field to loop and show each individual image.
The loop I have loops the correct amount of times (based on how many images there are in each matrix block), but it just shows the first image of the loop.
Here's the set up:
Section handle: products
Matrix field handle: imageTextSections
Block type handle: sectionBlock
Field handle: sectionBlockImages
Field type: Assets
{% set blocks = entry.imageTextSections.find({
with: [
'sectionBlock:sectionBlockImages'
]
}) %}
{% for block in blocks %}
...
{% for images in block.sectionBlockImages %}
{% set image = block.sectionBlockImages[0] ?? null %}
<img src="{{ image.url }}">
{% endfor %}
{% endfor %}
I figured that the following would work, but I get an error stating that the AssetFileModel.0 is not defined.
{% for images in block.sectionBlockImages %}
{% set image = images[0] ?? null %}
<img src="{{ image.url }}">
{% endfor %}
Any guidance would be greatly appreciated!
{% for images in block.sectionBlockImages %}
should be enough, there is no need to do{% set image = images[0] ?? null %}
since yourimage
variable should be the correct asset