You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: content/docs/3_reference/3_panel/3_fields/0_color/reference-article.txt
+131-22
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,12 @@ Intro: The `color` field supports multiple color notations, color picker, pre-de
12
12
13
13
Text:
14
14
15
+
(image: color.png)
16
+
17
+
## Field properties
18
+
19
+
(field-options: color)
20
+
15
21
## Usage
16
22
17
23
```yaml
@@ -20,9 +26,39 @@ color:
20
26
format: hsl # supports hex (default), rgb, hsl
21
27
```
22
28
23
-
(image: color.png)
24
29
25
-
## Pre-defined options
30
+
### In templates/snippets
31
+
32
+
```php
33
+
<?= $page->color()->escape('css') ?>
34
+
```
35
+
36
+
## Alpha
37
+
38
+
Use the `alpha` option (default: false) to activate alpha transparency support:
39
+
40
+
```yaml
41
+
color:
42
+
type: color
43
+
alpha: true
44
+
```
45
+
46
+
## Modes
47
+
48
+
With the `mode` option you control which elements of the color field are available. Possible values:
49
+
50
+
| Option | Description |
51
+
| ------ | ----------- |
52
+
|`picker` | show everything (default)|
53
+
|`input` | show only the input |
54
+
|`options` | show only options |
55
+
56
+
(image: color-field-modes.png)
57
+
58
+
59
+
## Options
60
+
61
+
### Pre-defined options
26
62
27
63
Allows adding a list of pre-defined colors that are shown as one-click options in the Panel.
28
64
@@ -46,39 +82,112 @@ If you name the colors, their name is shown in the Panel as well.
46
82
color:
47
83
type: color
48
84
options:
49
-
"Sunny rays": "#F8B195"
50
-
"First-love blush": "#F67280"
51
-
"Cherry blossom": "#C06C84"
52
-
"Morning gloom": "#6C5B7B"
53
-
"Midnight rain": "#355C7D"
85
+
"#F8B195": "Sunny rays"
86
+
"#F67280": "First-love blush"
87
+
"#C06C84": "Cherry blossom"
88
+
"#6C5B7B": "Morning gloom"
89
+
"#355C7D": "Midnight rain"
54
90
```
55
91
56
92
(image: color-field-names.png)
57
93
58
-
## Modes
94
+
<since v="4.1.0">
95
+
### Dynamic options
59
96
60
-
With the `mode` option you control which elements of the color field are available. Possible values:
97
+
Our options (link: docs/guide/blueprints/query-language text: query syntax) offers a very powerful way of to add an automatically generated option lists to a color field.
61
98
62
-
| Option | Description |
63
-
| ------ | ----------- |
64
-
|`picker` | show everything (default)|
65
-
|`input` | show only the input |
66
-
|`options` | show only options |
67
99
68
-
(image: color-field-modes.png)
100
+
```yaml
101
+
myColorField:
102
+
type: color
103
+
options:
104
+
type: query
105
+
query: kirby.option('my.colors')
106
+
```
69
107
70
-
## Alpha
108
+
The example above will get the color options from the `my.colors` config entry, which could look like:
109
+
110
+
```php "site/config/config.php"
111
+
// only values
112
+
return [
113
+
'my' => [
114
+
'colors' => [
115
+
'#3e3e3e',
116
+
'#aaa',
117
+
'#ddd',
118
+
]
119
+
]
120
+
];
121
+
122
+
// values -> labels
123
+
return [
124
+
'my' => [
125
+
'colors' => [
126
+
'#3e3e3e' => 'Color A' ,
127
+
'#aaa' => 'Color B',
128
+
'#ddd' => 'Color C',
129
+
]
130
+
]
131
+
];
132
+
```
71
133
72
-
Use the `alpha` option (default: false) to activate alpha transparency support:
134
+
You can start at the `site`, current `page`, `users` collection or the `kirby` instance to run your query.
135
+
136
+
#### Custom value and label
137
+
138
+
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.
73
139
74
140
```yaml
75
-
color:
141
+
myColorField:
76
142
type: color
77
-
alpha: true
143
+
options:
144
+
type: query
145
+
query: kirby.option('my.colors')
146
+
text: "{{ item.name }}"
147
+
value: "{{ item.hex }}"
78
148
```
79
149
80
-
## Use in templates/snippets
150
+
```php "site/config/config.php"
151
+
return [
152
+
'my' => [
153
+
'colors' => [
154
+
[
155
+
'name' => 'Color A',
156
+
'hex => '#3e3e3e',
157
+
],
158
+
[
159
+
'name' => 'Color B',
160
+
'hex => '#aaa',
161
+
],
162
+
[
163
+
'name' => 'Color C',
164
+
'hex => '#ddd',
165
+
]
166
+
]
167
+
]
168
+
];
169
+
```
81
170
82
-
```php
83
-
<?= $page->color()->escape('css') ?>
171
+
### Options via API
172
+
173
+
If the option queries are not enough or you need to pluck an external source for option data, you can use the API type.
174
+
175
+
```yaml
176
+
myColorField:
177
+
type: color
178
+
options:
179
+
type: api
180
+
url: https://your-options-api.com/colors.json
84
181
```
182
+
183
+
By default, the API type expects that the JSON endpoint returns an option array like this:
0 commit comments