<p>You already have the right array of Design Entries <a href="http://buildwithcraft.com/docs/templating/filters#group" rel="nofollow">grouped</a> by your Designer's user IDs with this line: </p>

<pre><code>{% set entriesByAuthor = designs|group('authorId') %}
</code></pre>

<p>Now all you have to do is to loop through this <code>entriesByAuthor</code> array. Use this syntax to <a href="http://twig.sensiolabs.org/doc/tags/for.html#iterating-over-keys-and-values" rel="nofollow">iterate over Keys and Values</a>:</p>

<pre><code>{% for key, value in entriesByAuthor %}
    {{ key }}: {{ value }}
{% endfor %}
</code></pre>

<p>Within the loop <code>key</code> is the <code>authorId</code> you grouped by and <code>value</code> is an array of EntryModels that share the same value for the <code>authorId</code> property. To list the Design entries you have to nest another for-loop and iterate over that array of EntryModels.</p>

<p>To retrieve other Designer data besides the ID you first need to grab the <a href="http://buildwithcraft.com/docs/templating/usermodel" rel="nofollow">UserModel</a>. Create a new ElementCriteriaModel with the <a href="http://buildwithcraft.com/docs/templating/craft.users" rel="nofollow"><code>authorId</code> as a parameter</a> and use the <code>first()</code> function to get the model.</p>

<pre><code>{# Grab all the Design Entries #}
{% set allDesigns = craft.entries.section('designs').limit(null).find() %}

{# Group by the authorId #}
{% set allDesignsByAuthor = allDesigns|group('authorId') %}

{# Loop through all Design Entries grouped by the authorId #}
{% for authorId, designsByAuthor in allDesignsByAuthor %}

    {# Grab the Designer's UserModel #}
    {% set designer = craft.users.id(authorId).first() %}

    &lt;h2&gt;{{ designer.name }}&lt;/h2&gt;

    {# List the Designer's Design Entries #}
    {% for design in designsByAuthor %}

        &lt;h3&gt;{{ design.title }}&lt;/h3&gt;

        {# List the Screenshots #}
        {% for image in design.screenshots %}

            &lt;a href="{{ designer.userAgencyUrl }}"&gt;
                &lt;img src="{{ image.url }}" alt="{{ image.title }}" /&gt;
            &lt;/a&gt;

        {% endfor %}

    {% endfor %}

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

<p>.</p>

<p><strong>Edit:</strong></p>

<p>Only now I got it, why you did this line to grab the UserModels with an ID of <code>allDesignsByAuthorId|keys</code>. This is in fact a good idea if you want list the users in another sort order than the user ID. Because I don't think you can do that with the approach I posted above.</p>

<p>Here's how you proceed after you fetched the Designers with a sort order of your desire. Loop through the array of Designers and create a new ElementCriteriaModel for each designer to grab the Designs using the Designer's user ID as the value for the <code>authorId</code> property.</p>

<pre><code>{# Grab all the Design Entries #}
{% set allDesigns = craft.entries.section('designs').limit(null).find() %}

{# Group by the authorId #}
{% set allDesignsByAuthorId = allDesigns|group('authorId') %}

{# Grab all of the users with the userIds in allDesignsByAuthorId #}
{% set designers = craft.users.id(allDesignsByAuthorId|keys).order('lastName') %}

{# Loop through the array of Designers #}
{% for designer in designers %}

    &lt;h2&gt;{{ designer.name }}&lt;/h2&gt;

    {# Grab all of the Design Entries created by this Designer #}
    {% set designs = craft.entries.section('designs').authorId(designer.id).find() %}

    {# List the entries #}
    {% for design in designs %}

        &lt;h3&gt;{{ design.title }}&lt;/h3&gt;

        {# List the Screenshots #}
        {% for image in design.screenshots %}

            &lt;a href="{{ designer.userAgencyUrl }}"&gt;
                &lt;img src="{{ image.url }}" alt="{{ image.title }}" /&gt;
            &lt;/a&gt;

        {% endfor %}

    {% endfor %}

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

<p>.</p>

<p><strong>2nd Edit:</strong></p>

<p>You only need to show one image for each Designer? Do it like so:</p>

<pre><code>{# Grab all the Design Entries #}
{% set allDesigns = craft.entries.section('designs').limit(null).find() %}

{# Group by the authorId #}
{% set allDesignsByAuthorId = allDesigns|group('authorId') %}

{# Grab all of the users with the userIds in allDesignsByAuthorId #}
{% set designers = craft.users.id(allDesignsByAuthorId|keys).order('lastName') %}

{# Loop through the array of Designers #}
{% for designer in designers %}

    {# Get the total number of Design Entries created by this Designer #}
    {% set totalDesigns = craft.entries.section('designs').authorId(designer.id).total() %}

    {# Grab the latest Design Entry created by this Designer #}
    {% set design = craft.entries.section('designs').authorId(designer.id).first() %}

    {# Grab the first screenshot image of that entry #}
    {% set image = design.screenshots.first() %}

    {# Output #}
    &lt;h2&gt;{{ designer.name }}&lt;/h2&gt;

    &lt;p&gt;{{ totalDesigns }}&lt;/p&gt;

    &lt;a href="{{ designer.userAgencyUrl }}"&gt;
        &lt;img src="{{ image.url }}" alt="{{ image.title }}" /&gt;
    &lt;/a&gt;

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

CC BY-SA 3.0
2014-09-01T12:26:09.283Z
Thank you very much for your detailed answer. I appreciate it! :) This info will definitely help when I want to create a list of design entries. Although for this, I am trying to list users (designers) who have posted design entries, and then for each user, display data from those entries. I will be displaying the total design entries each user has posted (which I have not coded yet) and I will pull the first image loaded from the image asset Design entry field 'screenshots' to display with each user listing on this Route page - which will list/paginate the users. I hope that makes sense! :)
Angela
CC BY-SA 3.0
2014-09-01T12:34:50.073Z
@Angela that's exactly what you get with this, a list of users who have posted design entries (→ `{% for designer in designers %}`) and then you loop through all the design entries each of these users have posted (→ `{% for design in designs %}`) and output the images (→ `{% for image in design.screenshots %}`). If you only want to show the first image of each design entry, you can replace the for-loop and use the `first()` function on the ElementCriteriaModel.
carlcs
CC BY-SA 3.0
2014-09-01T12:39:39.050Z
@Angela what do you mean with "I will be displaying the total design entries"? You need only the number of how many design entries that user has posted? And if I got you right, you want just one image to show up for each user. Which image should be shown if the user posted several entries, the first image of the latest entry?
carlcs
CC BY-SA 3.0
2014-09-01T12:57:20.593Z
Ah - thanks for the clarification! I was viewing that wrong. :) I will be displaying the total number of Design entries the user has posted. Yes - I will be pulling the 'first' image in the screenshots field from the 'latest' entry by that designer. Thanks for the help!
Angela
CC BY-SA 3.0
2014-09-01T13:27:11.307Z
Glad my answer works for you, @Angela. I just added the code to get the total number of entries.
carlcs
CC BY-SA 3.0
2014-09-01T13:46:55.190Z
Wow, very helpful @carlcs - Thank you! :)
Angela
CC BY-SA 3.0
2014-09-01T07:24:29.287Z
2014-09-01T13:20:07.407Z
2014-09-01T13:20:07.407Z
carlcs
<p>I am displaying a list of users with entries in the Design section using a Route. I am using this code for that and it seems to be working to display the correct users:</p>

<pre><code>{# Grab all the Design Entries #}
{% set designs = craft.entries.section('designs').find() %}

{# Group by the authorId #}
{% set entriesByAuthor = designs|group('authorId') %}

{# Grab all of the users with the userIds in entriesByAuthor #}
{% set designers = craft.users.id(entriesByAuthor|keys).group('members') %}
</code></pre>

<p>Although the issues I am having is trying to display data from fields from the entries by these users. For example, entries in the Design section also have images associated with them. I am trying to display the first image from the 'screenshots' field from the Designs section:</p>

<pre><code>{% for assets in designers %}
    {% for image in assets.screenshots %}

        {% if image %}
            &lt;a href="{{ user.userAgencyUrl }}"&gt;&lt;img src="{{ image.url }}" border="0" /&gt;&lt;/a&gt;
        {% endif %}         

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

<p>This does not give an error, but does not display anything for the image. I also tried adding .first() to this to get the first image from each entry, but that resulted in an error.</p>

<p>Any help will be appreciated! I have searched thoroughly for information about displaying entry fields from a user list (instead of just user fields) and I have not been able to find this information. (I also tried several other methods, such as relatedTo.)</p>

<p>Thanks!</p>

<users>
How do I display data from an entry field related to each user in a user listing page?
# How do I display data from an entry field related to each user in a user listing page?

(Asked by: username_0 on 2014-09-01)

I am displaying a list of users with entries in the Design section using a Route. I am using this code for that and it seems to be working to display the correct users:
{# Grab all the Design Entries #}
{% set designs = craft.entries.section('designs').find() %}

{# Group by the authorId #}
{% set entriesByAuthor = designs|group('authorId') %}

{# Grab all of the users with the userIds in entriesByAuthor #}
{% set designers = craft.users.id(entriesByAuthor|keys).group('members') %}

Although the issues I am having is trying to display data from fields from the entries by these users. For example, entries in the Design section also have images associated with them. I am trying to display the first image from the 'screenshots' field from the Designs section:
{% for assets in designers %}
    {% for image in assets.screenshots %}

        {% if image %}
            
        {% endif %}         

    {% endfor %}
{% endfor %}

This does not give an error, but does not display anything for the image. I also tried adding .first() to this to get the first image from each entry, but that resulted in an error.
Any help will be appreciated! I have searched thoroughly for information about displaying entry fields from a user list (instead of just user fields) and I have not been able to find this information. (I also tried several other methods, such as relatedTo.)
Thanks!

**Tags:** users


---

## 1 answers

### Answer by username_1 on 2014-09-01. Score: 1 | Accepted answer

You already have the right array of Design Entries grouped by your Designer's user IDs with this line: 
{% set entriesByAuthor = designs|group('authorId') %}

Now all you have to do is to loop through this entriesByAuthor array. Use this syntax to iterate over Keys and Values:
{% for key, value in entriesByAuthor %}
    {{ key }}: {{ value }}
{% endfor %}

Within the loop key is the authorId you grouped by and value is an array of EntryModels that share the same value for the authorId property. To list the Design entries you have to nest another for-loop and iterate over that array of EntryModels.
To retrieve other Designer data besides the ID you first need to grab the UserModel. Create a new ElementCriteriaModel with the authorId as a parameter and use the first() function to get the model.
{# Grab all the Design Entries #}
{% set allDesigns = craft.entries.section('designs').limit(null).find() %}

{# Group by the authorId #}
{% set allDesignsByAuthor = allDesigns|group('authorId') %}

{# Loop through all Design Entries grouped by the authorId #}
{% for authorId, designsByAuthor in allDesignsByAuthor %}

    {# Grab the Designer's UserModel #}
    {% set designer = craft.users.id(authorId).first() %}

    {{ designer.name }}

    {# List the Designer's Design Entries #}
    {% for design in designsByAuthor %}

        {{ design.title }}

        {# List the Screenshots #}
        {% for image in design.screenshots %}

            
                
            

        {% endfor %}

    {% endfor %}

{% endfor %}

.
Edit:
Only now I got it, why you did this line to grab the UserModels with an ID of allDesignsByAuthorId|keys. This is in fact a good idea if you want list the users in another sort order than the user ID. Because I don't think you can do that with the approach I posted above.
Here's how you proceed after you fetched the Designers with a sort order of your desire. Loop through the array of Designers and create a new ElementCriteriaModel for each designer to grab the Designs using the Designer's user ID as the value for the authorId property.
{# Grab all the Design Entries #}
{% set allDesigns = craft.entries.section('designs').limit(null).find() %}

{# Group by the authorId #}
{% set allDesignsByAuthorId = allDesigns|group('authorId') %}

{# Grab all of the users with the userIds in allDesignsByAuthorId #}
{% set designers = craft.users.id(allDesignsByAuthorId|keys).order('lastName') %}

{# Loop through the array of Designers #}
{% for designer in designers %}

    {{ designer.name }}

    {# Grab all of the Design Entries created by this Designer #}
    {% set designs = craft.entries.section('designs').authorId(designer.id).find() %}

    {# List the entries #}
    {% for design in designs %}

        {{ design.title }}

        {# List the Screenshots #}
        {% for image in design.screenshots %}

            
                
            

        {% endfor %}

    {% endfor %}

{% endfor %}

.
2nd Edit:
You only need to show one image for each Designer? Do it like so:
{# Grab all the Design Entries #}
{% set allDesigns = craft.entries.section('designs').limit(null).find() %}

{# Group by the authorId #}
{% set allDesignsByAuthorId = allDesigns|group('authorId') %}

{# Grab all of the users with the userIds in allDesignsByAuthorId #}
{% set designers = craft.users.id(allDesignsByAuthorId|keys).order('lastName') %}

{# Loop through the array of Designers #}
{% for designer in designers %}

    {# Get the total number of Design Entries created by this Designer #}
    {% set totalDesigns = craft.entries.section('designs').authorId(designer.id).total() %}

    {# Grab the latest Design Entry created by this Designer #}
    {% set design = craft.entries.section('designs').authorId(designer.id).first() %}

    {# Grab the first screenshot image of that entry #}
    {% set image = design.screenshots.first() %}

    {# Output #}
    {{ designer.name }}

    {{ totalDesigns }}

    
        
    

{% endfor %}

> **Comments:**
> **username_0**: Thank you very much for your detailed answer. I appreciate it! :) This info will definitely help when I want to create a list of design entries. Although for this, I am trying to list users (designers) who have posted design entries, and then for each user, display data from those entries. I will be displaying the total design entries each user has posted (which I have not coded yet) and I will pull the first image loaded from the image asset Design entry field 'screenshots' to display with each user listing on this Route page - which will list/paginate the users. I hope that makes sense! :)  
> **username_1**: @username_0 that's exactly what you get with this, a list of users who have posted design entries (→ `{% for designer in designers %}`) and then you loop through all the design entries each of these users have posted (→ `{% for design in designs %}`) and output the images (→ `{% for image in design.screenshots %}`). If you only want to show the first image of each design entry, you can replace the for-loop and use the `first()` function on the ElementCriteriaModel.  
> **username_1**: @username_0 what do you mean with "I will be displaying the total design entries"? You need only the number of how many design entries that user has posted? And if I got you right, you want just one image to show up for each user. Which image should be shown if the user posted several entries, the first image of the latest entry?  
> **username_0**: Ah - thanks for the clarification! I was viewing that wrong. :) I will be displaying the total number of Design entries the user has posted. Yes - I will be pulling the 'first' image in the screenshots field from the 'latest' entry by that designer. Thanks for the help!  
> **username_1**: Glad my answer works for you, @username_0. I just added the code to get the total number of entries.  
> **username_0**: Wow, very helpful @username_1 - Thank you! :)  

---

