Answers.Body: <p>Why do you try to fetch the image multiple times? </p>
  
  <pre><code>{% for image in block.logos %}
  </code></pre>
  
  <p>Will fetch the images and loop them <code>{% set logo = block.logos.first() %}</code> -> will fetch the first image again and again.</p>
  
  <pre><code>{% for image in block.logos %}
      {% set transformedImage = craft.imager.transformImage(image, { width: 312, height: 200, }) %}
      &lt;img src="{{ transformedImage.url }}" alt="{{ logo.title }}"&gt;
  {% endfor %}
  </code></pre>
  
  <p>Should work</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-02T18:01:44.630Z
Answers.LastActivityDate: 2018-07-02T18:01:44.630Z
Answers.UserDisplayName: Robin Schambach
Body: <p>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?</p>
  
  <p>I did try changing <code>{% set logo = block.logos.first() %}</code> to <code>{% set logo = block.logos.all() %}</code>, but that gave me an internal server error.</p>
  
  <pre><code>{% for block in entry.modules.all() %}
  
    {% if block.type == "logosBlock" %}
  
      {% for image in block.logos %}
  
          &lt;div class="logo-child"&gt;
  
            {% set logo = block.logos.first() %}
            {% set transformedImage = craft.imager.transformImage(logo, { width: 312, height: 200, }) %}
            &lt;img src="{{ transformedImage.url }}" alt="{{ logo.title }}"&gt;
          &lt;/div&gt;
  
        {% endfor %}
  
      &lt;/div&gt;
  
    {% endif %}
  
  {% endfor %}
  </code></pre>
  
Tags: <assets><matrix><plugin-imager>
Title: Output assets within a matrix block using Imager and Craft 3
ThreadText: # Output assets within a matrix block using Imager and Craft 3
  
  (Asked by: username_0 on 2018-07-02)
  
  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 %}
  
  ```
  
  **Tags:** assets, matrix, plugin-imager
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-07-02. Score: 2 | Accepted answer
  
  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
  
  
  ---
  
  