Answers.Body: <pre><code>{% for element in elements %}
      {% set asset = element.assetFieldHandle.one() %}
      {% if asset is not null %}
          &lt;img src="{{ asset.getUrl()"&gt;
      {% endif %}
  {% endfor %}
  </code></pre>
  
  <p>Take a look at <a href="https://docs.craftcms.com/v3/dev/element-queries/" rel="nofollow noreferrer">ElementQueries</a> and <a href="https://nystudio107.com/blog/handling-errors-gracefully-in-craft-cms#defensive-coding-in-twig" rel="nofollow noreferrer">how to handle errors</a> </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-18T16:17:44.693Z
Answers.LastActivityDate: 2018-07-18T16:17:44.693Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I created a field which uploads an image, and I want it to display it for each of my entries inside my for loop.</p>
  
  <p>What's the code I should use to do it?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-07-19T14:18:21.367Z
Comments.Text: Is the image a field used only with one entry? Or is it a different image added to each of the entries in your loop?
Comments.UserDisplayName: Ian Nebbiolo
Tags: <templating><assets><image>
Title: How to display a featured image in the list of entries
ThreadText: # How to display a featured image in the list of entries
  
  (Asked by: username_0 on 2018-07-18)
  
  I created a field which uploads an image, and I want it to display it for each of my entries inside my for loop.
  
  What's the code I should use to do it?
  
  **Tags:** templating, assets, image
  
  > **Comments:**
  > **username_1**: Is the image a field used only with one entry? Or is it a different image added to each of the entries in your loop?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2018-07-18. Score: 1
  
  ```
  {% for element in elements %}
      {% set asset = element.assetFieldHandle.one() %}
      {% if asset is not null %}
          <img src="{{ asset.getUrl()">
      {% endif %}
  {% endfor %}
  
  ```
  
  Take a look at [ElementQueries](https://docs.craftcms.com/v3/dev/element-queries/) and [how to handle errors](https://nystudio107.com/blog/handling-errors-gracefully-in-craft-cms#defensive-coding-in-twig)
  
  
  ---
  
  