How to list all User Groups and Users I'm nearly there on this one but could use some help. I want to list all User Groups, with all Users listed under each group. For bonus points, this all needs to be alphabetical (Group, then Users). Something like...

User Group A


User Name A
User Name B
etc...


User Group B


User Name A
User Name B
etc...


Here's what I have so far...

{% set userGroups = craft.userGroups.getAllGroups() %}

{% if userGroups|length %}
    {% for userGroup in userGroups %}
        &lt;h2&gt;{{ userGroup.name }}&lt;/h2&gt;
        {# list all users for this group #}
    {% endfor %}
{% endif %}


I just can't figure out how to loop through users for a userGroup.
Something like this should work:

{% set userGroups = craft.userGroups.getAllGroups() %}

{% if userGroups|length %}
    {% for userGroup in userGroups %}
        &lt;h2&gt;
            {{ userGroup.name }}
        &lt;/h2&gt;

        {% set users = craft.users.group(userGroup.handle) %}

        &lt;ul&gt;
        {% for user in users %}
            &lt;li&gt;
                {{ user.username }}
            &lt;/li&gt;
        {% endfor %}
        &lt;/ul&gt;
    {% endfor %}
{% endif %}