1

I'm having trouble trying to output assets from an Assets field that's within a Matrix block, using Imager. The code below is only outputting the first image that has been added, over and over for each asset, rather outputting each different asset. What am I doing wrong?

I did try changing {% set logo = block.logos.first() %} to {% set logo = block.logos.all() %}, but that gave me an internal server error.

{% for block in entry.modules.all() %}

  {% if block.type == "logosBlock" %}

    {% for image in block.logos %}

        <div class="logo-child">

          {% set logo = block.logos.first() %}
          {% set transformedImage = craft.imager.transformImage(logo, { width: 312, height: 200, }) %}
          <img src="{{ transformedImage.url }}" alt="{{ logo.title }}">
        </div>

      {% endfor %}

    </div>

  {% endif %}

{% endfor %}

1 Answer 1

2

Why do you try to fetch the image multiple times?

{% for image in block.logos %}

Will fetch the images and loop them {% set logo = block.logos.first() %} -> will fetch the first image again and again.

{% for image in block.logos %}
    {% set transformedImage = craft.imager.transformImage(image, { width: 312, height: 200, }) %}
    <img src="{{ transformedImage.url }}" alt="{{ logo.title }}">
{% endfor %}

Should work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.