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.

1 Answer 1


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 #}
    <img src="{{ assetFirst.getUrl({ height: 400 }) }}" alt="image.title"/>
{% endif %}

{% set assets = entry.assetsFieldHandle %}

{% if assets | length %}

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

{% endif %}
  • 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! Feb 21, 2016 at 19:16
  • If this was your second site it would have been a silly question ;-)
    – Natetronn
    Feb 21, 2016 at 19:16

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.