I have an image in a matrix-field, but can't get the url from it. dump(block.image.one().url) says NULL. My code is:

{% if entry.hero %}
  {% for block in entry.hero %}
    {% if block.type == 'hero' %}
      {% set heroImage = block.image.one() %}
      <div class="cell hero center padding-1" style="background-image: url({{ heroImage.url }});">
    {% endif %}
  {% endfor %}
{% endif %}

image.one() or image.first(), as well as .url or .getUrl() doesn't work the same.

What works though is {{ block.image.one().folderPath }}{{ block.image.one().filename }}

Does anyone know why? I'm on Craft CMS 3.3.15

  • 3
    Does the volume where your asset is have public urls enabled? – Seb Nov 28 '19 at 9:37
  • That's it, thanks! – Niko Nov 28 '19 at 10:16

The asset volume needs to have public urls enabled. Thanks seb.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.