<p>Here is a basic template that requires login, and checks that the currently logged-in user is in the user group 'clients'.</p>

<pre><code>{% extends "_layout" %}
{% requireLogin %}    

{% block content %}

    {% if currentUser.isInGroup( craft.userGroups.getGroupByHandle('clients') ) %}

        {# Only viewable by logged in users that belong to 'clients' user group #}    
        Restricted client content goes here.

    {% else %}

        {# Viewable by logged in users not in the user group 'clients' #}
        Notice to other user groups that this content is restricted to clients only.

    {% endif %}

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

<p>You may also want to check out <a href="https://craftcms.stackexchange.com/questions/4182/password-protected-area-with-unique-files/4184#4184">this question</a> for more examples.</p>

CC BY-SA 3.0
2014-10-22T17:36:24.593Z
Apparently I have to avoid saying "thanks" but hugely appreciated!
Liam
CC BY-SA 3.0
2014-10-22T17:40:10.680Z
Glad to help ;)
Douglas McDonald
CC BY-SA 3.0
2014-10-22T17:48:24.600Z
Some of this stuff is hard to track down in the docs, like `.getGroupByHandle()`, and requires you to go to the full [class reference documentation](http://buildwithcraft.com/classreference) to find. Generally things in there can be referenced in twig by the namespace (i.e. `craft`) followed by the service class (i.e. `userGroups`), followed by the method (.getGroupsByHandle).
Douglas McDonald
CC BY-SA 3.0
2014-10-22T17:22:17.953Z
2014-10-22T17:22:17.953Z
2017-04-13T12:51:00.253Z
Douglas McDonald
<p>I was wondering if someone could take a minute for a newbie to show the template code for a section index page that needs to be private - accessible only to "clients" (pre-registered as users in a private group - I am assuming).</p>

<p>I am confused about the permissions in the users section of the CP as they only show permissions to edit/view assets etc.... not templates.</p>

<p>Someone asked a similar question and the response was "yes it is easy - go look at the User Model" - however I am just starting to figure all this out so need a little help!!</p>

<p>Thank you</p>

<templating>
Password-Protect Sections - Newbie Template Code
# Password-Protect Sections - Newbie Template Code

(Asked by: username_0 on 2014-10-22)

I was wondering if someone could take a minute for a newbie to show the template code for a section index page that needs to be private - accessible only to "clients" (pre-registered as users in a private group - I am assuming).

I am confused about the permissions in the users section of the CP as they only show permissions to edit/view assets etc.... not templates.

Someone asked a similar question and the response was "yes it is easy - go look at the User Model" - however I am just starting to figure all this out so need a little help!!

Thank you

**Tags:** templating

---

## 1 answers

### Answer by username_1 on 2014-10-22. Score: 6 | Accepted answer

Here is a basic template that requires login, and checks that the currently logged-in user is in the user group 'clients'.
{% extends "_layout" %}
{% requireLogin %}    

{% block content %}

    {% if currentUser.isInGroup( craft.userGroups.getGroupByHandle('clients') ) %}

        {# Only viewable by logged in users that belong to 'clients' user group #}    
        Restricted client content goes here.

    {% else %}

        {# Viewable by logged in users not in the user group 'clients' #}
        Notice to other user groups that this content is restricted to clients only.

    {% endif %}

{% endblock %}

You may also want to check out this question for more examples.

> **Comments:**
> **username_0**: Apparently I have to avoid saying "thanks" but hugely appreciated!  
> **username_1**: Glad to help ;)  
> **username_1**: Some of this stuff is hard to track down in the docs, like `.getGroupByHandle()`, and requires you to go to the full [class reference documentation](http://buildwithcraft.com/classreference) to find. Generally things in there can be referenced in twig by the namespace (i.e. `craft`) followed by the service class (i.e. `userGroups`), followed by the method (.getGroupsByHandle).  

---

