Skip to content

Commit 29e72a0

Browse files
authored
docs(kno-13411): add number, color and list input field types to schema references (#1460)
* docs: add number, color and list input field types to schema references * fix: update link references * fix: use title property * docs: update list example
1 parent dcdf7f7 commit 29e72a0

3 files changed

Lines changed: 434 additions & 17 deletions

File tree

content/in-app-ui/message-types/schema-reference.mdx

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,114 @@ A checkbox that returns either true or false (checked or unchecked).
217217
}
218218
```
219219

220+
### Number
221+
222+
A numeric input field with optional min/max bounds and a unit label shown next to the input.
223+
224+
#### Settings
225+
226+
<Attributes>
227+
<Attribute
228+
name="required"
229+
type="boolean"
230+
description="Indicates this field is required"
231+
/>
232+
<Attribute
233+
name="description"
234+
type="string"
235+
description="An optional friendly description"
236+
/>
237+
<Attribute
238+
name="placeholder"
239+
type="string"
240+
description="An optional placeholder to display in the input"
241+
/>
242+
<Attribute
243+
name="default"
244+
type="number"
245+
description="The default numeric value"
246+
/>
247+
<Attribute
248+
name="min"
249+
type="number"
250+
description="The inclusive minimum allowed value"
251+
/>
252+
<Attribute
253+
name="max"
254+
type="number"
255+
description="The inclusive maximum allowed value"
256+
/>
257+
<Attribute
258+
name="unitLabel"
259+
type="string"
260+
description="A short label shown after the input (e.g. `px`, `kg`)"
261+
/>
262+
</Attributes>
263+
264+
#### Example
265+
266+
```json
267+
{
268+
"type": "number",
269+
"key": "ship_number",
270+
"label": "Ship number",
271+
"settings": {
272+
"description": "Displayed next to the hull ID",
273+
"placeholder": "0",
274+
"required": true,
275+
"default": 42,
276+
"min": 0,
277+
"max": 999999,
278+
"unitLabel": "TEU"
279+
}
280+
}
281+
```
282+
283+
### Color
284+
285+
A hex color input field that accepts values in `#RGB` or `#RRGGBB` format. Editors can also pick a color from the [branding variables](/template-editor/branding) defined on the environment, in which case the value is stored as a reference to that variable (e.g. `{{ vars.branding.primary_color }}`).
286+
287+
#### Settings
288+
289+
<Attributes>
290+
<Attribute
291+
name="required"
292+
type="boolean"
293+
description="Indicates this field is required"
294+
/>
295+
<Attribute
296+
name="description"
297+
type="string"
298+
description="An optional friendly description"
299+
/>
300+
<Attribute
301+
name="placeholder"
302+
type="string"
303+
description="An optional placeholder to display in the input"
304+
/>
305+
<Attribute
306+
name="default"
307+
type="string"
308+
description="The default hex color value"
309+
/>
310+
</Attributes>
311+
312+
#### Example
313+
314+
```json
315+
{
316+
"type": "color",
317+
"key": "accent_color",
318+
"label": "Accent color",
319+
"settings": {
320+
"description": "A hex color for the accent",
321+
"placeholder": "#000000",
322+
"required": true,
323+
"default": "#FF0000"
324+
}
325+
}
326+
```
327+
220328
### Select
221329

222330
A single select box that defines a static list of options for editors to pick from.
@@ -551,3 +659,78 @@ A JSON input field with schema validation.
551659
}
552660
}
553661
```
662+
663+
### List
664+
665+
A list of items, with an optional <a href="https://json-schema.org/" target="_blank">JSON Schema</a> that validates the structure of each item in the list.
666+
667+
#### Settings
668+
669+
<Attributes>
670+
<Attribute
671+
name="required"
672+
type="boolean"
673+
description="Indicates this field is required"
674+
/>
675+
<Attribute
676+
name="description"
677+
type="string"
678+
description="An optional friendly description"
679+
/>
680+
<Attribute name="default" type="array" description="The default list value" />
681+
<Attribute
682+
name="itemSchema"
683+
type="object"
684+
description="A JSON Schema object that validates the structure of each item in the list."
685+
/>
686+
</Attributes>
687+
688+
#### Example
689+
690+
```json
691+
{
692+
"type": "list",
693+
"key": "faqs",
694+
"label": "FAQs",
695+
"settings": {
696+
"description": "Frequently asked questions",
697+
"required": true,
698+
"default": [],
699+
"itemSchema": {
700+
"type": "object",
701+
"properties": {
702+
"question": { "type": "string", "title": "Question" },
703+
"answer": { "type": "string", "title": "Answer" }
704+
},
705+
"required": ["question", "answer"]
706+
}
707+
}
708+
}
709+
```
710+
711+
#### Usage
712+
713+
When a list input is referenced in a template, its value is decoded into a Liquid array so you can iterate over it and access each item's fields.
714+
715+
The most common pattern is to loop over the items:
716+
717+
```liquid title="Iterating over a list field"
718+
<dl>
719+
{% for faq in faqs %}
720+
<dt>{{ faq.question }}</dt>
721+
<dd>{{ faq.answer }}</dd>
722+
{% endfor %}
723+
</dl>
724+
```
725+
726+
You can also access a single item by index:
727+
728+
```liquid title="Accessing a list item by index"
729+
{{ faqs[0].question }}
730+
```
731+
732+
Note that printing the array directly with `{{ faqs }}` only works when the items are primitives (strings, numbers). For lists of objects, use the `json` filter to render the full value:
733+
734+
```liquid title="Rendering a list of objects"
735+
{{ faqs | json }}
736+
```

content/template-editor/partials/overview.mdx

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -148,30 +148,32 @@ Click a custom block to open the inspect panel to edit variable values. You can
148148

149149
You have two options, depending on your use case:
150150

151-
**1. Create a schema for your HTML partial and set the variable's input type to JSON.**
151+
**1. Create a schema for your HTML partial and set the variable's input type to list or JSON.**
152152

153-
When you create a [schema](/template-editor/partials/schema-reference) for your HTML partial, you can set the input type for a given variable to `json`. This will preserve the structure of the object or array of items that is passed in.
153+
When you create a [schema](/template-editor/partials/schema-reference) for your HTML partial, you can pick an input type that preserves the structure of the data passed in:
154154

155-
For example, if you want a partial to render a list of items, you can create a schema for your partial and pass your list to the partial input like this:
155+
- Use the [`list`](/template-editor/partials/schema-reference#list) input type when you want to pass an array of items (for example, a list of products or line items).
156+
- Use the [`json`](/template-editor/partials/schema-reference#json) input type when you want to pass a single object (for example, a user profile or other structured payload).
157+
158+
**Working with a list of items**
159+
160+
If you want a partial to render a list of items, you can define a `list` field in your schema and pass your array to the partial input.
156161

157162
```json title="A schema for an HTML partial's 'items' variable"
158163
[{
159-
"type": "json",
164+
"type": "list",
160165
"key": "items",
161166
"label": "Items list",
162167
"settings": {
163168
"required": true,
164169
"description": "A list of items to render",
165-
"schema": {
166-
"type": "array",
167-
"items": {
168-
"type": "object",
169-
"properties": {
170-
"name": { "type": "string" },
171-
"value": { "type": "string" }
172-
},
173-
"required": ["name", "value"]
174-
}
170+
"itemSchema": {
171+
"type": "object",
172+
"properties": {
173+
"name": { "type": "string" },
174+
"value": { "type": "string" }
175+
},
176+
"required": ["name", "value"]
175177
}
176178
}
177179
}]
@@ -180,16 +182,56 @@ Click a custom block to open the inspect panel to edit variable values. You can
180182
```liquid title="Passing a list of items to the partial's 'items' input"
181183
{{ data.items_list }}
182184
```
183-
Then, in the partial you can reference the list of items directly:
184-
```liquid title="Partial content with structured data"
185+
186+
Then, in the partial you can iterate over the items directly:
187+
188+
```liquid title="Partial content with a list of items"
185189
<ul>
186190
{% for item in items %}
187191
<li>{{ item.name }}: {{ item.value }}</li>
188192
{% endfor %}
189193
</ul>
190194
```
195+
196+
**Working with a single JSON object**
197+
198+
If you want a partial to render a single structured object, you can define a `json` field in your schema and pass your object to the partial input.
199+
200+
```json title="A schema for an HTML partial's 'user' variable"
201+
[{
202+
"type": "json",
203+
"key": "user",
204+
"label": "User",
205+
"settings": {
206+
"required": true,
207+
"description": "The user profile to render",
208+
"schema": {
209+
"properties": {
210+
"name": { "type": "string" },
211+
"email": { "type": "string" },
212+
"company": { "type": "string" }
213+
},
214+
"required": ["name", "email"]
215+
}
216+
}
217+
}]
218+
```
219+
220+
```liquid title="Passing an object to the partial's 'user' input"
221+
{{ recipient }}
222+
```
223+
224+
Then, in the partial you can reference the object's properties directly:
225+
226+
```liquid title="Partial content with a JSON object"
227+
<p>Hello {{ user.name }}</p>
228+
<p>Email: {{ user.email }}</p>
229+
{% if user.company != blank %}
230+
<p>Company: {{ user.company }}</p>
231+
{% endif %}
232+
```
191233
<br />
192-
You can follow a similar pattern for working with your full `data` payload, `recipient`, or other object [variables](/template-editor/variables) that are available in the workflow run scope; simply pass a Liquid reference to the variable into the partial input (i.e. `{{data}}`), then reference the object's properties within the partial content.
234+
You can follow a similar pattern for working with your full `data` payload, `recipient`, or other object [variables](/template-editor/variables) that are available in the workflow run scope; pass a Liquid reference to the variable into the partial input (i.e. `{{ data }}`), then reference the object's properties within the partial content.
193235
<br/>
194236
**2. Use Knock's Liquid helpers to transform your input data into a JSON string.**
195237

0 commit comments

Comments
 (0)