Answers.Body: <p>The asset volume needs to have public urls enabled. Thanks seb.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-28T10:17:16.143Z
Answers.LastActivityDate: 2019-11-28T10:17:16.143Z
Answers.UserDisplayName: Niko
Body: <p>I have an image in a matrix-field, but can't get the url from it.
  <code>dump(block.image.one().url)</code> says <code>NULL</code>. My code is: </p>
  
  <pre><code>{% if entry.hero %}
    {% for block in entry.hero %}
      {% if block.type == 'hero' %}
        {% set heroImage = block.image.one() %}
        &lt;div class="cell hero center padding-1" style="background-image: url({{ heroImage.url }});"&gt;
        &lt;/div&gt;
      {% endif %}
    {% endfor %}
  {% endif %}
  </code></pre>
  
  <p><code>image.one()</code> or <code>image.first()</code>, as well as <code>.url</code> or <code>.getUrl()</code> doesn't work the same.</p>
  
  <p>What works though is <code>{{ block.image.one().folderPath }}{{ block.image.one().filename }}</code></p>
  
  <p>Does anyone know why? I'm on Craft CMS 3.3.15</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-11-28T09:37:27.620Z
Comments.Text: Does the volume where your asset is have public urls enabled?
Comments.UserDisplayName: Seb
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-11-28T10:16:26.410Z
Comments.Text: That's it, thanks!
Comments.UserDisplayName: Niko
Tags: <templating><assets>
Title: How to get image url from matrix field
ThreadText: # How to get image url from matrix field
  
  (Asked by: username_0 on 2019-11-28)
  
  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
  
  **Tags:** templating, assets
  
  > **Comments:**
  > **username_1**: Does the volume where your asset is have public urls enabled?  
  > **username_0**: That's it, thanks!  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2019-11-28. Score: 4
  
  The asset volume needs to have public urls enabled. Thanks seb.
  
  
  ---
  
  