# Users

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

****

- Read more: <https://getkirby.com/docs/guide/blueprints/fields>
- Source: <https://github.com/getkirby/kirby/tree/5.5.3/config/fields/users.php>

****

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

<figure class="image"><a data-lightbox href="https://assets.getkirby.com/media/pages/docs/reference/panel/fields/users/58d8e03ce2-1717846665/users.png?width=1416&amp;height=404&amp;enlarge=0"><img alt="" class="rounded" height="264" loading="lazy" sizes="auto" src="https://assets.getkirby.com/media/pages/docs/reference/panel/fields/users/58d8e03ce2-1717846665/users.png?width=924&amp;height=264&amp;enlarge=0" srcset="https://assets.getkirby.com/media/pages/docs/reference/panel/fields/users/58d8e03ce2-1717846665/users.png?width=462&amp;height=132&amp;enlarge=0 462w, https://assets.getkirby.com/media/pages/docs/reference/panel/fields/users/58d8e03ce2-1717846665/users.png?width=690&amp;height=197&amp;enlarge=0 690w, https://assets.getkirby.com/media/pages/docs/reference/panel/fields/users/58d8e03ce2-1717846665/users.png?width=924&amp;height=264&amp;enlarge=0 924w, https://assets.getkirby.com/media/pages/docs/reference/panel/fields/users/58d8e03ce2-1717846665/users.png?width=1380&amp;height=394&amp;enlarge=0 1380w, https://assets.getkirby.com/media/pages/docs/reference/panel/fields/users/58d8e03ce2-1717846665/users.png?width=1416&amp;height=404&amp;enlarge=0 1848w" width="924"></a></figure>

## Example

```yaml
fields:
  authors:
    label: Authors
    type: users
```

## Field properties



<div class="table">
	<table class="parameters">
		<thead>
			<tr>
				<th>Name</th>
				<th>Type</th>
				<th>Default</th>

								<th>Description</th>
							</tr>
		</thead>
		<tbody>
						<tr>
				<td>
					default				</td>
				<td><code class="type type-array">array</code><span class="px-1 color-gray-400" aria-hidden="true">|</span><span class="sr-only">or</span><code class="type type-string">string</code><span class="px-1 color-gray-400" aria-hidden="true">|</span><span class="sr-only">or</span><code class="type type-bool">bool</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Default selected user(s) when a new page/file/user is created</td>
							</tr>
						<tr>
				<td>
					disabled				</td>
				<td><code class="type type-bool">bool</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>If <code class="type type-bool">true</code>, the field is no longer editable and will not be saved</td>
							</tr>
						<tr>
				<td>
					empty				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>The placeholder text if none have been selected yet</td>
							</tr>
						<tr>
				<td>
					help				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Optional help text below the field</td>
							</tr>
						<tr>
				<td>
					image				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Image settings for each item</td>
							</tr>
						<tr>
				<td>
					info				</td>
				<td><code class="type type-string">string</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Info text for each item</td>
							</tr>
						<tr>
				<td>
					label				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>The field label can be set as string or associative array with translations</td>
							</tr>
						<tr>
				<td>
					layout				</td>
				<td><code class="type type-string">string</code></td>

				<td data-label="Default:">
															<code>'list'</code>
									</td>

								<td>Changes the layout of the selected entries. Available layouts: <code class="type">list</code>, <code class="type">cardlets</code>, <code class="type">cards</code></td>
							</tr>
						<tr>
				<td>
					link				</td>
				<td><code class="type type-bool">bool</code></td>

				<td data-label="Default:">
															<code>true</code>
									</td>

								<td>Whether each item should be clickable</td>
							</tr>
						<tr>
				<td>
					max				</td>
				<td><code class="type type-int">int</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>The maximum number of allowed selected</td>
							</tr>
						<tr>
				<td>
					min				</td>
				<td><code class="type type-int">int</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>The minimum number of required selected</td>
							</tr>
						<tr>
				<td>
					multiple				</td>
				<td><code class="type type-bool">bool</code></td>

				<td data-label="Default:">
															<code>true</code>
									</td>

								<td>If <code class="type type-bool">false</code>, only a single one can be selected</td>
							</tr>
						<tr>
				<td>
					query				</td>
				<td><code class="type type-string">string</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Query for the items to be included in the picker</td>
							</tr>
						<tr>
				<td>
					required				</td>
				<td><code class="type type-bool">bool</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>If <code class="type type-bool">true</code>, the field has to be filled in correctly to be saved.</td>
							</tr>
						<tr>
				<td>
					search				</td>
				<td><code class="type type-bool">bool</code></td>

				<td data-label="Default:">
															<code>true</code>
									</td>

								<td>Enable/disable the search field in the picker</td>
							</tr>
						<tr>
				<td>
					size				</td>
				<td><code class="type type-string">string</code></td>

				<td data-label="Default:">
															<code>'auto'</code>
									</td>

								<td>Layout size for cards: <code class="type">tiny</code>, <code class="type">small</code>, <code class="type">medium</code>, <code class="type">large</code>, <code class="type">huge</code>, <code class="type">full</code></td>
							</tr>
						<tr>
				<td>
					store				</td>
				<td><code class="type type-string">string</code></td>

				<td data-label="Default:">
															<code>'uuid'</code>
									</td>

								<td>Whether to store UUID or ID in the content file of the model</td>
							</tr>
						<tr>
				<td>
					text				</td>
				<td><code class="type type-string">string</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Main text for each item</td>
							</tr>
						<tr>
				<td>
					translate				</td>
				<td><code class="type type-bool">bool</code></td>

				<td data-label="Default:">
															<code>true</code>
									</td>

								<td>If <code class="type type-bool">false</code>, the field will be disabled in non-default languages and cannot be translated. This is only relevant in multi-language setups.</td>
							</tr>
						<tr>
				<td>
					when				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Conditions when the field will be shown (since 3.1.0)</td>
							</tr>
						<tr>
				<td>
					width				</td>
				<td><code class="type type-string">string</code></td>

				<td data-label="Default:">
															<code>'1/1'</code>
									</td>

								<td>The width of the field in the field grid, e.g. <code class="type">1/1</code>, <code class="type">1/2</code>, <code class="type">1/3</code>, <code class="type">1/4</code>, <code class="type">2/3</code>, <code class="type">3/4</code></td>
							</tr>
					</tbody>
	</table>
</div>

## Default values

You can set a user email or user UUID as default value:

```yaml
fields:
  author:
    label: Author
    type: users
    default: johndoe@company.com # or user://H7jTLLW1
```
Or set the default to the current user by passing `true` as argument:

```yaml
fields:
  author:
    label: Author
    type: users
    default: true
```

## Limit selection

### Multiple or single mode

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

```yaml
fields:
  author:
    label: Author
    type: users
    multiple: false
```

### Maximum number of users

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

```yaml
fields:
  author:
    label: Author
    type: users
    max: 3
```


### Query users

You can use the `query` property to limit the users that can be selected:

```yaml
fields:
  author:
    label: Author
    type: users
    query: kirby.users.filterBy("role", "editor")
```

<h2 id="pagination"><a href="#pagination" tabindex="-1">Pagination</a></h2>
<p>Options in the pages picker are paginated. You can set the number of items per pagination page in the picker using the <code class="type">limit</code> property. The default setting is <code class="type">20</code>.</p>
<figure class="code">
<pre><code class="language-yaml">fields:
  pages:
    type: pages
    label: Select an item
    limit: 10</code></pre>
</figure>
<h2 id="search"><a href="#search" tabindex="-1">Search</a></h2>
<p>The pages picker shows a search field by default. If you want to remove it, you can switch it off with the <code class="type">search</code> option:</p>
<figure class="code">
<pre><code class="language-yaml">fields:
  pages:
    type: pages
    label: Select an item
    search: false</code></pre>
</figure>

## How to use in templates/snippets

### Single user

To convert a single user to a user object, use the [`toUser()`](/docs/reference/templates/field-methods/to-user) method:

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

### Multiple users

To convert multiple users to a users collection, use the [`toUsers()`](/docs/reference/templates/field-methods/to-users) method:

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