<p>According to the docs, the <a href="https://craftcms.com/classreference/models/UserModel#isInGroup-detail"><code>userModel.isInGroup()</code></a> method takes a "user group model, its handle, or ID" – in other words, it can only test for membership in a single group, not several.</p>

<p>What you want in this case is the <code>or</code> operator:</p>

<pre><code>{% if currentUser and (currentUser.isInGroup('userGroup1') or currentUser.isInGroup('userGroup2')) %}
    {# secret content #}
{% endif %}
</code></pre>

CC BY-SA 3.0
2016-09-03T19:18:58.870Z
Mahalo (thank you) @Mats, that does indeed work! And I swear I tried that....but I also swear that I read the isInGroup() method takes an array in addition to the group model, handle, or id... But now I can't find that either?  :-)
Shane Robinson
CC BY-SA 3.0
2016-09-03T08:29:46.510Z
2016-09-03T08:29:46.510Z
Mats Mikkel Rummelhoff
<p>Going to chime in here as I ran into a similar issue, and solved it a bit differently.</p>

<p>Instead of using group handles I was using a dynamic set of Group IDs. However, the problem still remains that <code>isInGroup()</code> doesn't support an array of handles or ids. So you gotta run some checks.</p>

<p>And, I think you can be little more dynamic using IDs.</p>

<pre><code>{% set coolArrayOfGroupIds = [2, 4, 5, 400] %}

{% if currentUser %}
    {% set allowedAccess = false %}

    {% for group in currentUser.getGroups() %}
        {% if group.id in coolArrayOfGroupIds %}
            {% set allowedAccess = true %}
        {% endif %}
    {% endfor %}

    {% if currentUser.admin or allowedAccess %}
        {# You win! Secrets Time #}
    {% endif %}

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

CC BY-SA 3.0
2016-09-29T16:44:28.953Z
Even better and closer to what I was looking for! Thanks so much, @Ian!!
Shane Robinson
CC BY-SA 3.0
2016-09-21T17:42:19.110Z
2016-09-21T17:42:19.110Z
Ian
<p>This is so simple in ExpressionEngine and yet I've tried everything for several hours and can't find a way to get it working in Craft???</p>

<p>I have 2 User Groups: <strong>userGroup1</strong>, <strong>userGroup2</strong></p>

<p>If the currently logged-in User belongs to <strong>either</strong> of those groups, show them "==SECRET CONTENT==" that guests (not logged-in users) do not see. </p>

<p>The following IF will only show "==SECRET CONTENT==" to userGroup1:</p>

<pre><code>{% if currentUser and currentUser.isInGroup('userGroup1') %}
    ==SECRET CONTENT==
{% endif #}
</code></pre>

<p>Now, based on everything I've found and read, it would seem the following <strong>SHOULD</strong> show ==SECRET CONTENT== to Users belonging to EITHER <strong>userGroup1</strong> OR <strong>userGroup2</strong>:</p>

<pre><code>{% if currentUser and currentUser.isInGroup('userGroup1','userGroup2') %}
    ==SECRET CONTENT==
{% endif #}
</code></pre>

<p>But it only shows ==SECRET CONTENT== to <strong>userGroup1</strong>. And if I switch the isInGroup values to the following, only <strong>userGroup2</strong> see the ==SECRET CONTENT==</p>

<pre><code>{% if currentUser and currentUser.isInGroup('userGroup2','userGroup1') %}
    ==SECRET CONTENT==
{% endif #}
</code></pre>

<p>I've tried Group IDs. I've tried every variation of formatting, array syntax, etc. 
I've searched the docs and StackExchange dozens of times...  </p>

<p>How can I display "==SECRET CONTENT==" to users belonging to <strong>userGroup1 OR userGroup2</strong> ??</p>

CC BY-SA 3.0
2016-09-03T13:57:10.697Z
A user is always in 1 group right?
Wouldn't twig syntax like
`{% if currentUser.group in ['usergroup1','usergroup2'] %}` work?
T.Skye
CC BY-SA 3.0
2016-09-03T14:58:52.570Z
@T.Skye: Not necessarily... A user can belong to multiple groups.
Lindsey D
CC BY-SA 3.0
2016-09-03T19:43:35.733Z
@T.Skye: That's exactly what I am trying/hoping to do... But the [currentUser global link](https://craftcms.com/docs/templating/global-variables) is a UserModel object and its [getGroups method link](https://craftcms.com/docs/templating/usermodel#getGroups) returns an array of Groups that user belongs to... Then I'd have to figure out how to match any of the user's groups against the groups I'm testing for... It got convoluted and I hoped there was an easier syntax...like you offered. But I can't find it and Mats solution below works for now until I understand Craft and Twig better. :)
Shane Robinson
<conditional><user-groups><current-user>
Show content if logged in user is in userGroup1 OR userGroup2?
# Show content if logged in user is in userGroup1 OR userGroup2?

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

This is so simple in ExpressionEngine and yet I've tried everything for several hours and can't find a way to get it working in Craft???
I have 2 User Groups: userGroup1, userGroup2
If the currently logged-in User belongs to either of those groups, show them "==SECRET CONTENT==" that guests (not logged-in users) do not see. 
The following IF will only show "==SECRET CONTENT==" to userGroup1:
{% if currentUser and currentUser.isInGroup('userGroup1') %}
    ==SECRET CONTENT==
{% endif #}

Now, based on everything I've found and read, it would seem the following SHOULD show ==SECRET CONTENT== to Users belonging to EITHER userGroup1 OR userGroup2:
{% if currentUser and currentUser.isInGroup('userGroup1','userGroup2') %}
    ==SECRET CONTENT==
{% endif #}

But it only shows ==SECRET CONTENT== to userGroup1. And if I switch the isInGroup values to the following, only userGroup2 see the ==SECRET CONTENT==
{% if currentUser and currentUser.isInGroup('userGroup2','userGroup1') %}
    ==SECRET CONTENT==
{% endif #}

I've tried Group IDs. I've tried every variation of formatting, array syntax, etc. 
I've searched the docs and StackExchange dozens of times...  
How can I display "==SECRET CONTENT==" to users belonging to userGroup1 OR userGroup2 ??

**Tags:** conditional, user-groups, current-user

> **Comments:**
> **username_1**: A user is always in 1 group right? Wouldn't twig syntax like `{% if currentUser.group in ['usergroup1','usergroup2'] %}` work?  
> **username_2**: @username_1: Not necessarily... A user can belong to multiple groups.  
> **username_0**: @username_1: That's exactly what I am trying/hoping to do... But the [currentUser global link](https://craftcms.com/docs/templating/global-variables) is a UserModel object and its [getGroups method link](https://craftcms.com/docs/templating/usermodel#getGroups) returns an array of Groups that user belongs to... Then I'd have to figure out how to match any of the user's groups against the groups I'm testing for... It got convoluted and I hoped there was an easier syntax...like you offered. But I can't find it and Mats solution below works for now until I understand Craft and Twig better. :)  

---

## 2 answers

### Answer by username_4 on 2016-09-21. Score: 6 | Accepted answer

Going to chime in here as I ran into a similar issue, and solved it a bit differently.
Instead of using group handles I was using a dynamic set of Group IDs. However, the problem still remains that isInGroup() doesn't support an array of handles or ids. So you gotta run some checks.
And, I think you can be little more dynamic using IDs.
{% set coolArrayOfGroupIds = [2, 4, 5, 400] %}

{% if currentUser %}
    {% set allowedAccess = false %}

    {% for group in currentUser.getGroups() %}
        {% if group.id in coolArrayOfGroupIds %}
            {% set allowedAccess = true %}
        {% endif %}
    {% endfor %}

    {% if currentUser.admin or allowedAccess %}
        {# You win! Secrets Time #}
    {% endif %}

{% endif %}

> **Comments:**
> **username_0**: Even better and closer to what I was looking for! Thanks so much, @username_4!!  

---

### Answer by username_3 on 2016-09-03. Score: 11

According to the docs, the userModel.isInGroup() method takes a "user group model, its handle, or ID" – in other words, it can only test for membership in a single group, not several.
What you want in this case is the or operator:
{% if currentUser and (currentUser.isInGroup('userGroup1') or currentUser.isInGroup('userGroup2')) %}
    {# secret content #}
{% endif %}

> **Comments:**
> **username_0**: Mahalo (thank you) @Mats, that does indeed work! And I swear I tried that....but I also swear that I read the isInGroup() method takes an array in addition to the group model, handle, or id... But now I can't find that either?  :-)  

---

