Viewtemplate
Overview
viewTemplate is a reusable template, instantiable dynamically at runtime via create_view(...) or statically in children[] via templateRef.
Fields
Key |
Type |
Default |
Required |
Description |
|---|---|---|---|---|
|
string |
none |
Yes |
Fixed to |
|
string |
none |
Yes |
Template id |
|
object |
none |
Yes |
Template root control; cannot contain |
{
"type": "viewTemplate",
"id": "menu_item",
"node": {
"type": "button",
"children": [
{"type": "label", "id": "title", "labelProps": {"text": "Item"}}
]
}
}
Templateref
templateRef may only appear in children[]; it is a parser directive, not a runtime control type.
Key |
Type |
Default |
Required |
Description |
|---|---|---|---|---|
|
string |
none |
Yes |
Fixed to |
|
string |
none |
Yes |
Instance root node id |
|
string |
none |
Yes |
The |
|
object |
|
No |
Replaces slot content by the template's internal slot id |
|
object |
|
No |
Overrides local fields by the template's internal relative path |
{
"type": "templateRef",
"id": "wifi_item",
"templateId": "menu_item",
"overrides": {
"title": {
"labelProps": {"text": "Wi-Fi"}
}
}
}
A template can expose replaceable subtrees with the slot parser directive in children[]:
{
"type": "viewTemplate",
"id": "settings_card",
"node": {
"type": "container",
"children": [
{"type": "slot", "id": "content", "children": []}
]
}
}
slot.id must be non-empty. An instance fills the matching content via slots. When a slot is not provided, the slot's own
children is used as default content; it is empty if there is no default. slot exists only in the parser stage, not as a runtime control type.
An unknown slot, a duplicate slot id, or a slot left in the normal view tree causes an error.
overrides keys use a template-internal relative path; an empty string or "." denotes the template root node. Overrides can only replace local fields;
overriding id, type, children, node, templateId, slots, or overrides is not allowed. When both slots and
overrides are present, slots are filled first, then overrides are applied.