Fetch Single asset without for loop? I've got a Assets field which is limited to 1 asset inside a Matrix field. Is there a better way to fetch the image without using a forloop?

At the minute I've got:

{% for image in block.backgroundImage %}
    {{ image.getUrl() }}
{% endfor %}


But it just doesn't seem right using a forloop when I know there is only one image.

Thanks
You can call the first() function to just get the first image:



{% set image = block.backgroundImage.first() %}
{{ image.getUrl() }}


But this will fail if there is no image. So to be safe, you need:

{% set image = block.backgroundImage.first() %}
{% if image %}
    {{ image.getUrl() }}
{% endif %}