Color
The color
field supports multiple color notations, a color picker, pre-defined colors, custom color names, and transparency.
Field properties
Name | Type | Default | Description |
---|---|---|---|
alpha | bool |
false |
Whether to allow alpha transparency in the color |
autofocus | bool |
– | Sets the focus on this field when the form loads. Only the first field with this label gets |
default | – | Default value for the field, which will be used when a page/file/user is created | |
disabled | bool |
– | If true , the field is no longer editable and will not be saved |
format | string |
hex |
The CSS format (hex, rgb, hsl) to display and store the value |
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 | |
mode | string |
picker |
Change mode to disable the color picker (input ) or to only show the options as toggles |
options | array |
[] |
List of colors that will be shown as buttons to directly select them |
placeholder | – | Optional placeholder value that will be shown when the field is empty | |
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. |
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: 1/1 , 1/2 , 1/3 , 1/4 , 2/3 , 3/4
|
Usage
In templates/snippets
Alpha
Use the alpha
option (default: false) to activate alpha transparency support:
Modes
With the mode
option you control which elements of the color field are available. Possible values:
Option | Description |
---|---|
picker |
show everything (default) |
input |
show only the input |
options |
show only options |
Options
Pre-defined options
Allows adding a list of pre-defined colors that are shown as one-click options in the Panel.
If you name the colors, their name is shown in the Panel as well.
Since 4.1.0
Dynamic options
Our options query syntax offers a powerful way of adding automatically generated option lists to a color field.
The example above will get the color options from the my.colors
config entry, which could look like:
You can start at the site
, current page
, users
collection, or the kirby
instance to run your query.
Custom value and label
To customize the stored value and displayed label, you can be more specific when defining the query: text
and value
can be defined with the help of our string template language to get exactly what you want as the result.
Options via API
If the option queries are not enough or you need to pluck an external source for option data, you can use the API type.
By default, the API type expects that the JSON endpoint returns an option array like this: