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 %}

    <h1>{{ category.title }}</h1>

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

    {% for user in group %}
        <li>{{ user.name }}</li>
    {% 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?

  • If you just output {{ category.slug }} onto the page, is it what you're expecting?
    – Brad Bell
    Jan 3, 2016 at 19:33
  • no, I am trying to output the all the users of the user group that has the same handle as the current category. Jan 3, 2016 at 20:03
  • Right, so have you verified that {{ category.slug }} outputs either teachers or candidates?
    – Brad Bell
    Jan 3, 2016 at 20:05

1 Answer 1


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.