deftemplate
- Last UpdatedNov 05, 2023
- 2 minute read
Use the deftemplate command to create instances of a template. Templates are useful when you must include the same text in many places.
You can also use templates to build behavior libraries into projects. Since they are parametric, templates can be shared among different projects.
Platform support
This element is fully supported on XR-Windows, XR-Portable Windows, XR-Portable iOS, XR-Portable Android, and XR-P WASM platforms.
|
XR-WIN |
XR-P-WIN |
XR-P-IOS |
XR-P-AND |
XR-P-WASM |
|---|---|---|---|---|
|
Full support |
Full support |
Full support |
Full support |
Full support |
|
|
|
|
|
|
To define a template
-
Include your template code inside a deftemplate tag.
-
Put placeholders with the syntax %placeholder% where you want to parametrize the code.
Note: Placeholders in the template require unique names that do not contain spaces or special characters.
Code example
This is a code example for the deftemplate node.
<deftemplate name="tbutton">
<button name="c_%id%" show="true" position="%position%" size="40 40" >
<rect>
<rect show="true" image="ICO_DPI_Avatar.png" order="5" position="0 5" size="40 30"/>
<text show="true" text="%text%" font="Baveuse,true,40" format="Left Up" order="2" position="60 0" size="400 50" color="1 1 1 1"/>
</rect>
<rect>
<rect image="ICO_DPI_Avatar_sel.png" order="5" show="true" position="0 5" size="40 30" />
<text show="true" text="%text%" font="Baveuse,true,40" format="Left Up" order="2" position="60 0" size="400 50" color="0 0.9 0 1"/>
</rect>
</button>
<rect name="c_%id%s" show="true" image="ICO_SelectorAvatar.png" order="8" position="%position2%" size="450 54" />
</deftemplate>
See Also
Position
The deftemplate element must be inside a context node, such as Context or Global.
Fields
These are the fields for deftemplate command.
|
Fields |
Type |
Use |
Default value |
Description |
|---|---|---|---|---|
|
name |
sstring |
Mandatory |
Not set |
The name of the template. |