<p>I'm not sure about displaying "the first image from the asset folder" but, you can display the first asset as it's situated in the entry itself. Would that work? Maybe something like this?</p>

<pre><code>{% set assetFirst = entry.myAssetsField.first() %}

{% if assetFirst %}
    {# or use getImg() (or either alias img/url): https://craftcms.com/docs/templating/assetfilemodel #}
    &lt;img src="{{ assetFirst.getUrl({ height: 400 }) }}" alt="image.title"/&gt;
{% endif %}

{% set assets = entry.assetsFieldHandle %}

{% if assets | length %}

    {% for asset in assets %}
        {# https://craftcms.com/docs/templating/assetfilemodel#simple-output #}
        &lt;a href="{{ file.url }}"&gt;{{ file }}&lt;/a&gt;
    {% endfor %}

{% endif %}
</code></pre>

CC BY-SA 3.0
2016-02-21T19:16:02.913Z
This worked perfect Nathan, exactly what I was after.  Not sure if it was a silly question or not (my first Craft site), but thanks for the help!
conormcafee
CC BY-SA 3.0
2016-02-21T19:16:44.687Z
If this was your second site it would have been a silly question ;-)
Natetronn
CC BY-SA 3.0
2016-02-21T19:00:32.633Z
2016-02-21T19:00:32.633Z
Natetronn
<p>Basically, for every entry that I add to my 'Portfolio' channel, it creates a sub-folder inside assets/portfolio.</p>

<p>For example I have:</p>

<ul>
<li>assets/portfolio/entry-one</li>
<li>assets/portfolio/entry-two</li>
</ul>

<p>On my portfolio page, for each entry I want to display the first image from its asset folder and also get the url of every image in the folder.  </p>

<p>Can anyone think of a solution that would allow me to do this? Can't figure out how to target each individual folder.  I know you can target folders by ID, but unless this can be somehow done dynamically in a loop it will not suit this situation. </p>

<assets><forloop><channels>
How can I loop through a Channel entries asset folder?
# How can I loop through a Channel entries asset folder?

(Asked by: username_0 on 2016-02-21)

Basically, for every entry that I add to my 'Portfolio' channel, it creates a sub-folder inside assets/portfolio.

For example I have:

* assets/portfolio/entry-one
* assets/portfolio/entry-two

On my portfolio page, for each entry I want to display the first image from its asset folder and also get the url of every image in the folder.

Can anyone think of a solution that would allow me to do this? Can't figure out how to target each individual folder. I know you can target folders by ID, but unless this can be somehow done dynamically in a loop it will not suit this situation.

**Tags:** assets, forloop, channels

---

## 1 answers

### Answer by username_1 on 2016-02-21. Score: 1 | Accepted answer

I'm not sure about displaying "the first image from the asset folder" but, you can display the first asset as it's situated in the entry itself. Would that work? Maybe something like this?
{% set assetFirst = entry.myAssetsField.first() %}

{% if assetFirst %}
    {# or use getImg() (or either alias img/url): https://craftcms.com/docs/templating/assetfilemodel #}
    
{% endif %}

{% set assets = entry.assetsFieldHandle %}

{% if assets | length %}

    {% for asset in assets %}
        {# https://craftcms.com/docs/templating/assetfilemodel#simple-output #}
        {{ file }}
    {% endfor %}

{% endif %}

> **Comments:**
> **username_0**: This worked perfect Nathan, exactly what I was after.  Not sure if it was a silly question or not (my first Craft site), but thanks for the help!  
> **username_1**: If this was your second site it would have been a silly question ;-)  

---

