<p>The <a href="http://buildwithcraft.com/docs/templating/usermodel#getGroups" rel="nofollow">UserModel</a> has a <a href="http://buildwithcraft.com/docs/templating/usermodel" rel="nofollow">getGroups()</a> function which:</p>

<blockquote>
  <p>Returns an array of
  <a href="http://buildwithcraft.com/docs/templating/usergroupmodel" rel="nofollow">UserGroupModel</a>
  objects that the user belongs to.</p>
</blockquote>

<p>Since a user can belong to multiple usergroups, you have to loop through the array containing them:</p>

<pre class="lang-twig prettyprint-override"><code>{% set thePartner = craft.users.username( craft.request.getSegment(2) ) %}

# Loop through array of UserGroupModels #
{% for group in thePartner.getGroups() %}
    # Print name of current UserGroupModel #
    {{ group.name }}
{% endfor %}
</code></pre>

<p>If you are sure the user only belongs to one group, you can fetch the first UserGroupModel from like this:</p>

<pre class="lang-twig prettyprint-override"><code>{% set thePartner = craft.users.username( craft.request.getSegment(2) ) %}

# Get first UserGroupModel #
{% set group = thePartner.getGroups().first %}

# Print name #
{{ group.name }}
</code></pre>

CC BY-SA 3.0
2014-08-02T18:24:04.493Z
Perfect, thank you -- that did the trick nicely.
Shanan Galligan
CC BY-SA 3.0
2014-08-02T14:43:49.303Z
2014-08-02T14:43:49.303Z
Victor
<p>This seems simple, but I cannot get it to render -- how do display a user's User Group? Assuming I set the user in segment 2:</p>

<pre><code>{% set thePartner = craft.users.username( craft.request.getSegment(2) ) %}
This Is My User Group: {% ???? %}
</code></pre>

<templating><users>
How do you display a user's User Group?
# How do you display a user's User Group?

(Asked by: username_0 on 2014-08-02)

This seems simple, but I cannot get it to render -- how do display a user's User Group? Assuming I set the user in segment 2:
{% set thePartner = craft.users.username( craft.request.getSegment(2) ) %}
This Is My User Group: {% ???? %}

**Tags:** templating, users

---

## 1 answers

### Answer by username_1 on 2014-08-02. Score: 3 | Accepted answer

The UserModel has a getGroups() function which:

Returns an array of
  UserGroupModel
  objects that the user belongs to.

Since a user can belong to multiple usergroups, you have to loop through the array containing them:
{% set thePartner = craft.users.username( craft.request.getSegment(2) ) %}

# Loop through array of UserGroupModels #
{% for group in thePartner.getGroups() %}
    # Print name of current UserGroupModel #
    {{ group.name }}
{% endfor %}

If you are sure the user only belongs to one group, you can fetch the first UserGroupModel from like this:
{% set thePartner = craft.users.username( craft.request.getSegment(2) ) %}

# Get first UserGroupModel #
{% set group = thePartner.getGroups().first %}

# Print name #
{{ group.name }}

> **Comments:**
> **username_0**: Perfect, thank you -- that did the trick nicely.  

---

