<p>Your source is set to : </p>

<pre><code>{{ entry.getPhoto.getUrl('user') }}
</code></pre>

<p>When in order to access an image, you need to give the array index (as you have in your set statement):</p>

<pre><code>{{ entry.getPhoto[0].getUrl('user')
</code></pre>

<p>or better yet, as you have already set it to a variable</p>

<pre><code>{{ userImage.getUrl('user') }}
</code></pre>

<p>In full, while adding in to appropriate code for eager loading your transforms:</p>

<pre><code>{% set entries = craft.users({
    group: 'coWorkers',
    orderBy: 'lastName',
    with: [
       [
           'getPhoto', 
           { withTransforms: ['user'] }
       ],
    ]
}) %}

{% for entry in entries %}

    {% set userImage = entry.getPhoto[0] ?? null %}

    {% if userImage %}

        &lt;figure class="portrait"&gt;
            &lt;a href="{{ userURL }}"&gt;
                &lt;img class="portrait_image"
                     src="{{ userImage.getUrl('user') }}"
                     alt="{{ entry.fullName }}" /&gt;
            &lt;/a&gt;
        &lt;/figure&gt;

    {% endif %}

{% endfor %}
</code></pre>

<p>If you need any further information, the <a href="https://docs.craftcms.com/v3/dev/eager-loading-elements.html" rel="nofollow noreferrer">Official Documentation</a> does a excellent job of explaining how to implement this on the front end for craft 3</p>

CC BY-SA 4.0
2023-02-24T19:33:04.170Z
Hi, Meanwhile we are on craft 4 and the syntax for getting user fotos is: `{{ user.photo.url('transformHandle') }}` and my eager load syntax is this `['photo', { withTransforms: ['transformHandle'] }]`. When I try  `{{ user.photo[0].url('transformHandle') }}` it throughs an error. Do you know how to handle this on craft 4? Because it ain't eager loading the fotos...
outline4
CC BY-SA 4.0
2019-10-14T21:45:09.370Z
2019-10-14T21:45:09.370Z
nicholasthompson
<p>I've been trying to eager load user Photos, but it does not seem to work. </p>

<p>Here's my stripped down code: </p>

<pre><code>{% set entries = craft.users({
    group: 'coWorkers',
    orderBy: 'lastName',
    with: [
        'getPhoto',
    ],

}) %}

{% for entry in entries %}
    {% set userImage = entry.getPhoto[0] ?? null %}
    {% if userImage|length %}
        &lt;figure class="portrait"&gt;
            &lt;a href="{{ userURL }}"&gt;&lt;img class="portrait_image" src="{{ entry.getPhoto.getUrl('user') }}" alt="{{ entry.fullName }}" /&gt;&lt;/a&gt;
        &lt;/figure&gt;
    {% endif %}
{% endfor %}
</code></pre>

<p>No photos are displayed. </p>

<p>Preferrably I would eager load with the transform as well: </p>

<pre><code>{% set entries = craft.users({
    group: 'mitarbeiter',
    orderBy: 'lastName',
    with: [
        ['getPhoto', { withTransforms: ['user'] }],
    ],

}) %}   
</code></pre>

<p>In Craft 2 I could eager load the following way: </p>

<pre><code>{% set entries = craft.users({
    group: 'mitarbeiter',
    orderBy: 'lastName',
    with: [
        'getPhotoUrl(320)',
    ],

}) %}   
</code></pre>

<p>Anyone has done this before? </p>

<p>Cheers<br>
Stefan</p>

<users><eager-loading>
How to eager load user Images (photoUrl)?
# How to eager load user Images (photoUrl)?

(Asked by: username_0 on 2019-10-08)

I've been trying to eager load user Photos, but it does not seem to work. 
Here's my stripped down code: 
{% set entries = craft.users({
    group: 'coWorkers',
    orderBy: 'lastName',
    with: [
        'getPhoto',
    ],

}) %}

{% for entry in entries %}
    {% set userImage = entry.getPhoto[0] ?? null %}
    {% if userImage|length %}
        
            
        
    {% endif %}
{% endfor %}

No photos are displayed. 
Preferrably I would eager load with the transform as well: 
{% set entries = craft.users({
    group: 'mitarbeiter',
    orderBy: 'lastName',
    with: [
        ['getPhoto', { withTransforms: ['user'] }],
    ],

}) %}   

In Craft 2 I could eager load the following way: 
{% set entries = craft.users({
    group: 'mitarbeiter',
    orderBy: 'lastName',
    with: [
        'getPhotoUrl(320)',
    ],

}) %}   

Anyone has done this before? 
Cheers
Stefan

**Tags:** users, eager-loading


---

## 1 answers

### Answer by username_1 on 2019-10-14. Score: 1

Your source is set to : 
{{ entry.getPhoto.getUrl('user') }}

When in order to access an image, you need to give the array index (as you have in your set statement):
{{ entry.getPhoto[0].getUrl('user')

or better yet, as you have already set it to a variable
{{ userImage.getUrl('user') }}

In full, while adding in to appropriate code for eager loading your transforms:
{% set entries = craft.users({
    group: 'coWorkers',
    orderBy: 'lastName',
    with: [
       [
           'getPhoto', 
           { withTransforms: ['user'] }
       ],
    ]
}) %}

{% for entry in entries %}

    {% set userImage = entry.getPhoto[0] ?? null %}

    {% if userImage %}

        
            
                
            
        

    {% endif %}

{% endfor %}

If you need any further information, the Official Documentation does a excellent job of explaining how to implement this on the front end for craft 3

> **Comments:**
> **username_0**: Hi, Meanwhile we are on craft 4 and the syntax for getting user fotos is: `{{ user.photo.url('transformHandle') }}` and my eager load syntax is this `['photo', { withTransforms: ['transformHandle'] }]`. When I try  `{{ user.photo[0].url('transformHandle') }}` it throughs an error. Do you know how to handle this on craft 4? Because it ain't eager loading the fotos...  

---

