A user select field that allows to select one or multiple users

The users field can be used to select one or more users. It's perfect to store authors for an article, for example.


    label: Authors
    type: users


Option Type Required Default Description
default mixed Default selected user(s) when a new Page/File/User is created
disabled bool If true, the field is no longer editable and will not be saved
help mixed Optional help text below the field
label mixed The field label can be set as string or associative array with translations
max int The maximum number of allowed selected users
min int The minimum number of required selected users
multiple bool true If false, only a single user can be selected
required bool If true, the field has to be filled in correctly to be saved.
translate bool true If false, the field will be disabled in non-default languages and cannot be translated. This is only relevant in multi-language setups.
width string 1/1 The width of the field in the field grid. Available widths: 1/1, 1/2, 1/3, 1/4, 2/3, 3/4

Default values

The default value of the user field is the current user. But you can change this default value to any existing user:

    label: Author
    type: users

Maximum number of users

You can set the maximum number of users that can be selected:

    label: Author
    type: users
    max: 3

Multiple or single mode

If you only want to select a single user, set multiple mode to false (default is true)

    label: Author
    type: users
    multiple: false

Accessing selected users in templates

Single user

To convert a single user to a user object, use the toUser() method:

<?php if($user = $page->author()->toUser()): ?>
  <?= $user->username() ?>
<?php endif ?>

Multiple users

To convert multiple users to a users collection, use the toUsers() method:

$users =  $page->authors()->toUsers();
foreach($users as $user): ?>
  <?= $user->username() ?>
<?php endforeach ?>