<p>I believe your problem lies in the parameter for user group. In Twig, you don't need the brackets if you're already in brackets. You just reference the variable and fields directly. So instead of:</p>

<pre><code>{% set group = craft.users.group('{{ category.slug }}') %}
</code></pre>

<p>Try this:</p>

<pre><code>{% set group = craft.users.group(category.slug) %}
</code></pre>

<p>You see, the ElementCriteriaModel that's parsing the parameter for group doesn't run all its function arguments through Twig. So you're confusing it by throwing braces in there. Just give it the variable and field without quotes or braces and it should work smashingly, provided that <code>category.slug</code> is the same as a group <code>slug</code>.</p>

CC BY-SA 3.0
2016-01-04T13:22:17.900Z
2016-01-04T13:22:17.900Z
Bryan Redeagle
<p>I am building a community website that currently have two user groups but it might increase so I am trying to automate everything. The current groups are: 'teachers' &amp; 'candidates'.</p>

<p>I have a channel section named 'Community' and for this channel I have setup a category group called 'Community' that has two categories named as the user groups: 'teachers' &amp; 'candidates'.</p>

<p>I am trying to display a list of all the registered users in a specific group as you are loading the category template.</p>

<p>This is the template that is being loaded:</p>

<pre><code>{% extends "community/index" %}

{% set title = category.title %}

{% block main %}

    &lt;h1&gt;{{ category.title }}&lt;/h1&gt;

    {% set group = craft.users.group('{{ category.slug }}') %}

    {% for user in group %}
        &lt;li&gt;{{ user.name }}&lt;/li&gt;
    {% endfor %}

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

<p>I was thinking that since the <code>{{ category.slug }}</code> has the same name as the user group, it can work but apparently not...</p>

<p>Can someone help me to understand how to relate the two?</p>

CC BY-SA 3.0
2016-01-03T19:33:20.087Z
If you just output `{{ category.slug }}` onto the page, is it what you're expecting?
Brad Bell
CC BY-SA 3.0
2016-01-03T20:03:52.310Z
no, I am trying to output the all the users of the user group that has the same handle as the current category.
LessMore Creative Studio
CC BY-SA 3.0
2016-01-03T20:05:14.127Z
Right, so have you verified that `{{ category.slug }}` outputs either `teachers` or `candidates`?
Brad Bell
<categories><user-groups>
User groups in relation to categories
# User groups in relation to categories

(Asked by: username_0 on 2016-01-03)

I am building a community website that currently have two user groups but it might increase so I am trying to automate everything. The current groups are: 'teachers' & 'candidates'.
I have a channel section named 'Community' and for this channel I have setup a category group called 'Community' that has two categories named as the user groups: 'teachers' & 'candidates'.
I am trying to display a list of all the registered users in a specific group as you are loading the category template.
This is the template that is being loaded:
{% extends "community/index" %}

{% set title = category.title %}

{% block main %}

    {{ category.title }}

    {% set group = craft.users.group('{{ category.slug }}') %}

    {% for user in group %}
        {{ user.name }}
    {% endfor %}

{% endblock %} 

I was thinking that since the {{ category.slug }} has the same name as the user group, it can work but apparently not...
Can someone help me to understand how to relate the two?

**Tags:** categories, user-groups

> **Comments:**
> **username_1**: If you just output `{{ category.slug }}` onto the page, is it what you're expecting?  
> **username_0**: no, I am trying to output the all the users of the user group that has the same handle as the current category.  
> **username_1**: Right, so have you verified that `{{ category.slug }}` outputs either `teachers` or `candidates`?  

---

## 1 answers

### Answer by username_2 on 2016-01-04. Score: 2 | Accepted answer

I believe your problem lies in the parameter for user group. In Twig, you don't need the brackets if you're already in brackets. You just reference the variable and fields directly. So instead of:
{% set group = craft.users.group('{{ category.slug }}') %}

Try this:
{% set group = craft.users.group(category.slug) %}

You see, the ElementCriteriaModel that's parsing the parameter for group doesn't run all its function arguments through Twig. So you're confusing it by throwing braces in there. Just give it the variable and field without quotes or braces and it should work smashingly, provided that category.slug is the same as a group slug.


---

