Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to restrict access to items in a channel using some form of custom user permissions however I don't appear to be able to create or set custom read permissions for a channel using crafts permissions as they currently are, I'm therefore trying to do something using either user groups or custom fields on the user and validate if a user has access that way.

I'm hoping this is along the right lines, although it doesn't seem ideal, so is it possible to check if a user is in a certain user group elegantly using twig?

I can do {{ if currentUser.admin }} and I'm guessing I could therefore do something like {{if 'groupnamewithaccess' in currentUser.groups }}

share|improve this question
up vote 10 down vote accepted

I believe what you're looking for is 'isInGroup'

{% if currentUser.isInGroup('groupHandle') %}

It will also accept an actual group object or a group ID as well.

There is also getGroups:

{{ currentUser.getGroups() }}

Will return an array of UserGroupModels all of the groups the user belongs to.

And finally, can:

{{ currentUser.can('permissionName') }}

Will check if the current user has the given permissions, whether that was indirectly assigned to them in a group, or directly assigned to them as a user.

share|improve this answer
This is perfect, isInGroup works perfectly. – Darren Jul 20 '14 at 0:34
Any chance that we can get something like this to work? Sometimes I just need to make sure that a user is NOT a member of a group. Right now I don't see a simple way to make this determination. {% if !currentUser.isInGroup('groupHandle') %} – David Aaron McInnis Sep 23 '14 at 22:48
@DavidAaronMcInnis Use {% if not currentUser.isInGroup('groupHandle') %} – Brad Bell Sep 24 '14 at 3:14
Can isInGroup be accessed from within a plugin? – David Aaron McInnis Feb 17 '15 at 19:07

If you're looking to check groups and/or permissions from your plugin controller with PHP, you can access the same methods.

//get the current user from craft
$user = craft()->userSession->getUser();

//check if the current user has permission to edit certain entries
$checkPerms = $user->can('editEntries: 27');

$checkPerms will return a boolean

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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