If you have Craft Pro, you can access your site’s users from your templates via craft.users
. It returns an {entry:templating/elementcriteriamodel:link} object.
{% for author in craft.users.group('authors') %}
<li><a href="{{ url('authors/'~author.id) }}">{{ author.name }}</a></li>
{% endfor %}
craft.users
supports the following parameters:
Only fetch admin users. Possible values include '1'
and 'not 1'
.
{# Fetch all the admins #}
{% set admins = craft.users.admin('1') %}
{# Fetch all the non-admins #}
{% set nonAdmins = craft.users.admin('not 1') %}
Only fetch users that have a given permission.
{% set authors = craft.users.can('createEntries:5') %}
You can see a list of the permissions Craft comes with here.
Only fetch users with the given email.
Only fetch users with the given first name.
If set to true
, users will be returned in the same order as the IDs entered in the id
param.
Only fetch users that belong to a given user group(s), referenced by its handle.
Only fetch users that belong to a given user group(s), referenced by its ID.
Only fetch the user with the given ID.
Indexes the results by a given property. Possible values include 'id'
and 'username'
.
Fetch users based on their last login date.
Only fetch users with the given last name.
Limits the results to X users.
Skips the first X users. For example, if you set offset(1)
, the would-be second user returned becomes the first.
The order the users should be returned in. Possible values include 'username'
, 'firstName'
, 'lastName'
, 'email'
, 'preferredLocale'
, 'status'
, 'lastLoginDate'
, 'dateCreated'
, and 'dateUpdated'
, as well as any textual custom field handles. If you want the users to be sorted in descending order, add “desc
” after the property name (ex: 'lastLoginDate desc'
). The default value is 'username'
.
Only fetch users that are related to certain other elements. (See {entry:docs/relations:link} for the syntax options.)
Only fetch users that match a given search query. (See {entry:docs/searching:link} for the syntax and available search attributes.)
Only fetch users with the given status. Possible values are 'active'
, 'locked'
, 'suspended'
, 'pending'
, archived'
, and null
. The default value is 'active'
. null
will return all users regardless of status.
Only fetch the user with the given username.