2

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 }});">
      </div>
    {% 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

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

1 Answer 1

4

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

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.