Cheat Sheet: craft.users

{# craft.users tag #}
{% set users = craft.users.first() %}
{% set users = craft.users.last() %}
{% set users = craft.users.find() %}
{% set users = craft.users.ids() %}
{% set users = craft.users.total() %}

{% set user = craft.users({
  id:         id OR 'not id' OR '1,2,3' OR [1,2,3],
  fixedOrder: true OR false,

  admin:      true OR false,
  email:      'email',
  firstName:  'firstName',
  group:      'groupHandle', 
  groupId:    id,
  indexBy:    'id,username'
  lastName:   'lastName',
  limit:      number,
  offset:     number,
  order:      'username,firstName,lastName,email,language,status,lastLoginDate desc',
  status:     'active,locked,suspended,pending,archived,*',
  username:   'username',
  
  can:        'createEntries:5',

  relatedTo:  AssetFileModel, EntryModel, UserModel, 
              CategoryModel, TagModel,
              elementId,
              [ arrayOfModels, arrayOfModels, arrayOfModels ],
              [ 1, 2, 3 ],
              craft.assets, craft.categories, craft.entries,
              craft.tags, craft.users

  search:     'salty dog'           containing both "salty" and "dog"
              '"salty dog"'         containing the exact phrase "salty dog"
              'salty OR dog'        containing either "salty" or "dog" (or both)
              'salty -dog'          containing "salty" but not "dog"
              'body:salty'          containing "salty" in the "body" field
              'body:salty'          body:dog containing both "salty" and "dog" 
                                    in the "body" field
              'body:*'              containing anything within the "body" field
              'salty locale:en_us'  containing "salty" in the locale "en_us"
              'salt*'               containing a word that begins with "salt"
              '*ty'                 containing a word that ends with "ty"
              '*alt*'               containing a word that contains "alt",

}) %}

{% for user in users %}
  
  {# UserModel #}

  {# Properties #}
  {{ user.admin }}           {# true,false #}
  {{ user.dateCreated }}
  {{ user.dateUpdated }}
  {{ user.email }}
  {{ user.fullName }}
  {{ user.friendlyName }}
  {{ user.groups }}
  {{ user.firstName }}
  {{ user.lastName }}
  {{ user.lastLoginDate }}
  {{ user.name }}
  {{ user.next }}
  {{ user.id }}
  {{ user.isCurrent }}
  {{ user.photoUrl }}
  {{ user.preferredLocale }}
  {{ user.prev }}
  {{ user.status }}          {# active, locked, suspended, pending, archived #}
  {{ user.username }}
             
  {# Methods #}
  {{ user.can( 'permission' ) }}
  {{ user.getFullName() }}
  {{ user.getFriendlyName() }}
  {{ user.getGroups() }}
  {{ user.getName() }}
  {{ user.getPhotoUrl( size) }}
  {{ user.isInGroup( groupHandle OR groupId OR UserGroupModel ) }}

  {% set prev = user.getPrev( params ) %}
  {% set next = user.getNext( params ) %}
  {% if prev %} <a href="/link-to-prev-user">{{ prev.username }}</a> {% endif %}
  {% if next %} <a href="/link-to-next-user">{{ next.username }}</a> {% endif %}

{% endfor %}

Level up in Craft CMS with practical examples, snippets, and patterns.
Craft The Planet emails are sent out several times a week.