Toggle
Yes/no or on/off toggle
The toggle field is perfect for simple on/off or yes/no states.

Example
fields:
toggle:
label: Include in menu?
type: toggle
text:
- "no"
- "yes"
Field properties
Property | Type | Default | Description |
---|---|---|---|
after |
– | Optional text that will be shown after the input |
|
autofocus |
bool | – | Sets the focus on this field when the form loads. Only the first field with this label gets |
before |
– | Optional text that will be shown before the input |
|
default |
– | Default value which will be saved when a new page/user/file is created |
|
disabled |
bool | – | If |
help |
– | Optional help text below the field |
|
icon |
string | – | Optional icon that will be shown at the end of the field |
label |
– | The field label can be set as string or associative array with translations |
|
required |
bool | – | If |
text |
– | Sets the text next to the toggle. The text can be a string or an array of two options. The first one is the negative text and the second one the positive. The text will automatically switch when the toggle is triggered. |
|
translate |
bool | true |
If |
when |
– | Conditions when the field will be shown (since 3.1.0) |
|
width |
string | 1/1 |
The width of the field in the field grid. Available widths: |
Simple toggle field translated
fields:
toggle:
label: Toggle
type: toggle
text:
en: Include in menu?
de: Im Menü anzeigen?
Text toggle
fields:
toggle:
label: Toggle
type: toggle
text:
- Nope
- Yay
Text toggle translated
fields:
toggle:
label: Toggle
type: toggle
text:
-
en: Nope
de: Och nö
-
en: Yay
de: Juhu
The field content will either be 'true' or 'false'.
How to use in templates/snippet
Convert to a proper boolean:
$bool = $page->toggle()->toBool();
Do something depending on field value:
<?php
if ($page->toggle()->toBool() === true) {
// do this
} else {
// do that
}