Radical Design Course by Jack McDade

From the creator of Statamic

Learn how to make your websites standout and be remembered.

This course is the most refreshing take on teaching design that I've come across.

— Mikaël Sévigny, Developer

User Roles Fieldtype

Pro Feature

Use this fieldtype to create a relationship with User Roles.

User Roles Fieldtype UI
The User Roles Fieldtype in action!

Overview

The User Role fieldtype gives your users a way to pick one or more User Roles to attach to the current entry. What you do with that relationship is up to you, but most likely you'll be either listing users or combining it with the User:Is tag to protect content or areas of the frontend.

Data Storage

The User Role fieldtype stores the handle of a single group as a string, or an array of handles if max_items is greater than 1.

Templating

The User Role fieldtype uses augmentation to return the title and handle of each Role. You can use pass these values into the {{ user:is }} tag to protect content.

The following example assumes max_items has been set to 1.

{{ user:is :role="role_field:handle" }}
You are a {{ role_field:title }}. Nice!
{{ /user:is }}
{{-- Using Statamic Tags --}}
<statamic:user:is
:role="$role_field->handle"
>
You are a {{ $role_field->title }}. Nice!
</statamic:user:is>
 
{{-- Using Fluent Tags --}}
@if(Statamic::tag('user:is')->role($role_field->handle)->fetch())
You are a {{ $role_field->title }}. Nice!
@endif

Options

max_items

integer

The maximum number of user roles that may be selected.

mode

string

Set the UI style for this field. Can be one of default (Stack Selector), select (Select Dropdown) or typeahead (Typeahead Field).

HR: Section
Learn More!

Create a relationship with a User Role

Docs

Tags

HR: Section
Docs feedback

Submit improvements, related content, or suggestions through Github.

Betterify this page →