<p>You have to make sure you enabled the option <code>Assets in this volume have public urls</code> in your volume settings at <code>/admin/settings/assets/volumes/</code>.</p>

<p>This checkbox is disabled by default thus your <code>getUrl()</code> function will always return an empty string/null.</p>

CC BY-SA 3.0
2018-02-05T09:10:34.867Z
2018-02-05T09:10:34.867Z
Robin Schambach
<p>In Craft 3, one of my 'User' fields is an assets type field with one selectable asset ('profilePicture').</p>

<p>I have routing setup to load my template when a url looks like:</p>

<pre><code>domain.com/person/firstname-lastname
</code></pre>

<p>In my template I am getting the appropriate user with: </p>

<pre><code>{% set secondSegment = craft.request.getSegment(2) %}

{% set people = craft.users.group('family') %}

{% for person in people %}
    {% set personName = person.firstName|lower ~ "-" ~ person.lastName|lower %}
    {% if secondSegment == personName %}
        {% set currentUser = person %}
    {% endif %}
{% endfor %}
</code></pre>

<p>All that works - I can query most fields, but I can't work out how to get my asset.</p>

<p>Works:</p>

<pre><code>{{ currentUser.myTextField }}
</code></pre>

<p>None of these work (returns nothing and no error):</p>

<p>1.</p>

<pre><code>{{ currentUser.profilePicture[0].url }}
</code></pre>

<p>2.</p>

<pre><code>{% set asset = currentUser.profilePicture.first() %}

{% if asset %}
    {{ asset.getUrl }}
{% endif %}
</code></pre>

<p>3.</p>

<pre><code>{% for asset in currentUser.profilePicture %}
    {{ asset.getUrl }}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2018-02-05T05:51:37.690Z
Did you enable URLs for this asset sources? If not the `getUrl` function will return null
Robin Schambach
CC BY-SA 3.0
2018-02-05T09:04:46.967Z
@RobinSchambach Arg! <Smacks head> Thanks! If you want to write it up I'll mark it as correct.
Adam George
<assets><craft3><assets-field>
How to return asset from custom user field
# How to return asset from custom user field

(Asked by: username_0 on 2018-02-05)

In Craft 3, one of my 'User' fields is an assets type field with one selectable asset ('profilePicture').
I have routing setup to load my template when a url looks like:
domain.com/person/firstname-lastname

In my template I am getting the appropriate user with: 
{% set secondSegment = craft.request.getSegment(2) %}

{% set people = craft.users.group('family') %}

{% for person in people %}
    {% set personName = person.firstName|lower ~ "-" ~ person.lastName|lower %}
    {% if secondSegment == personName %}
        {% set currentUser = person %}
    {% endif %}
{% endfor %}

All that works - I can query most fields, but I can't work out how to get my asset.
Works:
{{ currentUser.myTextField }}

None of these work (returns nothing and no error):
1.
{{ currentUser.profilePicture[0].url }}

2.
{% set asset = currentUser.profilePicture.first() %}

{% if asset %}
    {{ asset.getUrl }}
{% endif %}

3.
{% for asset in currentUser.profilePicture %}
    {{ asset.getUrl }}
{% endfor %}

**Tags:** assets, craft3, assets-field
> **Comments:**
> **username_1**: Did you enable URLs for this asset sources? If not the `getUrl` function will return null  
> **username_0**: @RobinSchambach Arg! <Smacks head> Thanks! If you want to write it up I'll mark it as correct.  

---

## 1 answers

### Answer by username_1 on 2018-02-05. Score: 1 | Accepted answer

You have to make sure you enabled the option `Assets in this volume have public urls` in your volume settings at `/admin/settings/assets/volumes/`.

This checkbox is disabled by default thus your `getUrl()` function will always return an empty string/null.


---

