Skip to main content
2 of 6
improved answer
Douglas McDonald
  • 13.5k
  • 25
  • 57

It is very easy within your templates to define requirements for whether the page itself, or portions of the content are displayed, and/or route the user to another page if they do not meet the page requirements. For example, you can check whether the user is logged in, belongs to a particular group, is the author of the entry, has a specific permission (and even create your own permissions), and any combination of the above. Here are a few examples, but in general there is a lot flexibility here.

{% if currentUser %}
    ...
{% endif %}

{% if craft.session.isLoggedIn %}
    ...
{% endif %}

{% if currentUser.can('viewContent') %}
    ...
{% endif %}

{% if currentUser.isInGroup( group ) %}
    ...
{% endif %}

{% if currentUser.id == entry.author.id %}
    ...
{% endif %}

When retrieving entries using ElementCriteriaModel you can also find by author, group, relatedTo, etc. so that you can only show the user links to entries that they have access to. To find entries where the author is the currentUser, for example, you could use something like this:

{% set entries = craft.entries.section('blog').authorId(currentUser.id).find() %}
{% for entry in entries %}
    <a href="{{ entry.url }}">{{ entry.title }}</a>
{% endfor %}

For more information have a look at the documentation on UserModel, craft.session, craft.users, and ElementCriteriaModel.

Douglas McDonald
  • 13.5k
  • 25
  • 57