<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>

CC BY-SA 4.0
2018-07-18T16:17:44.693Z
2018-07-18T16:17:44.693Z
Robin Schambach
<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>

CC BY-SA 4.0
2018-07-19T14:18:21.367Z
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?
Ian Nebbiolo
<templating><assets><image>
How to display a featured image in the list of entries
# 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 %}
        
    {% endif %}
{% endfor %}

Take a look at ElementQueries and how to handle errors


---

