3

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

Liam
  • 33
  • 2

1 Answers1

6

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.

Douglas McDonald
  • 13,457
  • 24
  • 57