Manage text variables within design templates.
Text variables enable dynamic content replacement in design templates. Variables are stored as key-value pairs and can be referenced in text blocks for automated content updates.
// Configure a text block that displays 'Hello, World'const block = engine.block.create('text');engine.block.setText(block, 'Hello, {{name}}!');engine.variable.setString('name', 'World');Color, number, image and typeface variables hold typed values. A block property bound to one of
them with engine.block.setVariableBinding follows every change of the variable.
engine.variable.setColor('brand', { r: 1, g: 0, b: 0, a: 1 });engine.block.setVariableBinding(fill, 'fill/color/value', 'brand');The scene saves its variables, and undo reverts their changes. A variable set while no scene exists waits for the next scene: that scene takes it when it is created or loaded, and its value replaces the loaded one.
A value set holds alternative values for some variables, such as worst-case texts or a client’s
copy. The active set wins over the default values. A call without a target uses the layer that
the scene shows, so getString returns what setString wrote.
const longNames = engine.variable.createValueSet('Long names');engine.variable.setString('name', 'Maximiliane', { target: { valueSet: longNames } });engine.variable.setActiveValueSet(longNames);engine.variable.getString('name'); // 'Maximiliane'engine.variable.getString('name', { target: 'Default' }); // 'World'Implements#
IVariableAPI
Constructors#
Methods#
findAll()#
Get all text variable names of the scene, or of the variables that wait for a scene.
Returns#
string[]
List of variable names.
Implementation of#
IVariableAPI.findAllSignature#
findAll(): string[]setString()#
Set a text variable’s value. Creates the variable if it doesn’t exist.
The scene saves its variables, and undo reverts their changes. A variable set while no scene exists waits for the
next scene. That scene takes it when it is created or loaded, as this setter without a target writes it. A value of
another type than the loaded variable is dropped.
A new key must not be empty, start or end with whitespace, contain {{ or }}, or be reserved: scene_root and
keys that start with ubq..
{{ or }}, or be reserved: scene_root and
keys that start with ubq..Parameters#
| Parameter | Type | Description |
|---|---|---|
key |
string |
The variable’s key. |
value |
string |
The text value to assign. |
options? |
VariableOptions |
The layer to write. By default the active value set when it holds the key, else the default value. |
Returns#
void
Implementation of#
IVariableAPI.setStringSignature#
setString(key: string, value: string, options?: VariableOptions): voidgetString()#
Get a text variable’s value.
Parameters#
| Parameter | Type | Description |
|---|---|---|
key |
string |
The variable’s key. |
options? |
VariableOptions |
The layer to read. By default the value that the scene shows. |
Returns#
string
The text value of the variable.
Implementation of#
IVariableAPI.getStringSignature#
getString(key: string, options?: VariableOptions): stringremove()#
Remove a variable of any type from the engine.
Bound properties keep their last value and their binding, so direct writes
to them still fail with BLOCK.PROPERTY_BOUND. Setting a variable with the
same key and type again makes them follow it again.
Parameters#
| Parameter | Type | Description |
|---|---|---|
key |
string |
The variable’s key to remove. |
options? |
VariableOptions |
The layer to remove from. By default, and with the target 'Default', the variable goes with its value in every value set. A value set target removes only the value of that set. |
Returns#
void
Implementation of#
IVariableAPI.removeSignature#
remove(key: string, options?: VariableOptions): voidcreateValueSet()#
Create an empty value set in the scene. A value set holds alternative values for some scene variables; write them
with the target { valueSet: id }. The scene saves its sets, and undo reverts their changes.
{ valueSet: id }. The scene saves its sets, and undo reverts their changes.Parameters#
| Parameter | Type | Description |
|---|---|---|
name |
string |
The name of the set. It must be unique among the sets of the scene, must not be empty, and must not start or end with whitespace. |
Returns#
string
The id of the new set. The scene saves it, so it stays the same across saves and loads.
Implementation of#
IVariableAPI.createValueSetSignature#
createValueSet(name: string): stringdestroyValueSet()#
Destroy a value set and its values. When the set is active, no set is active afterwards.
Parameters#
| Parameter | Type | Description |
|---|---|---|
set |
string |
The id of the set. |
Returns#
void
Implementation of#
IVariableAPI.destroyValueSetSignature#
destroyValueSet(set: string): voidsetValueSetName()#
Rename a value set. The id stays, and an active set stays active.
Parameters#
| Parameter | Type | Description |
|---|---|---|
set |
string |
The id of the set. |
name |
string |
The new name, valid as for createValueSet. |
Returns#
void
Implementation of#
IVariableAPI.setValueSetNameSignature#
setValueSetName(set: string, name: string): voidgetValueSetName()#
Get the name of a value set.
Parameters#
| Parameter | Type | Description |
|---|---|---|
set |
string |
The id of the set. |
Returns#
string
The name of the set.
Implementation of#
IVariableAPI.getValueSetNameSignature#
getValueSetName(set: string): stringfindAllValueSets()#
Get the value sets of the scene.
Returns#
string[]
The ids of the sets in creation order, empty when no scene exists.
Implementation of#
IVariableAPI.findAllValueSetsSignature#
findAllValueSets(): string[]findValueSetByName()#
Find a value set by its name.
Parameters#
| Parameter | Type | Description |
|---|---|---|
name |
string |
The name of the set. |
Returns#
string
The id, or null when no set of the scene has this name or no scene exists.
Implementation of#
IVariableAPI.findValueSetByNameSignature#
findValueSetByName(name: string): stringsetActiveValueSet()#
Activate a value set, or no set. The values of the active set win over the default values in text, bound
properties and getters. Exports show the active set, as the canvas does.
A scene has one active set and saves it. Undo reverts the change.
Parameters#
| Parameter | Type | Description |
|---|---|---|
set |
string |
The id of the set, or null to show the default values. |
Returns#
void
Implementation of#
IVariableAPI.setActiveValueSetSignature#
setActiveValueSet(set: string): voidgetActiveValueSet()#
Get the active value set.
Returns#
string
The id of the active set, or null when no set is active or no scene exists.
Implementation of#
IVariableAPI.getActiveValueSetSignature#
getActiveValueSet(): stringrename()#
Rename a variable of any type. The value, the type and the values in every value set move to the new key. Every
block property bound to the variable follows the new key and keeps its value. For a text variable, every
{{key}} token in text blocks and page titles is rewritten too. A key inside a longer expression or a statement,
such as {% if key %}, is not renamed.
{{key}} token in text blocks and page titles is rewritten too. A key inside a longer expression or a statement,
such as {% if key %}, is not renamed.Parameters#
| Parameter | Type | Description |
|---|---|---|
from |
string |
The current key of the variable. |
to |
string |
The new key. It must not be empty, start or end with whitespace, contain {{ or }}, name another variable, or be reserved: scene_root and keys that start with ubq.. |
Returns#
void
Implementation of#
IVariableAPI.renameSignature#
rename(from: string, to: string): voidsetColor()#
Set a color variable. Creates the variable if it doesn’t exist.
Every block property bound to the variable takes the color that the scene shows.
If a bound property rejects the value, the call throws its error, but the variable and the other bound
properties change anyway.
A new key must not be empty, start or end with whitespace, contain {{ or }}, or be reserved: scene_root and
keys that start with ubq..
{{ or }}, or be reserved: scene_root and
keys that start with ubq..Parameters#
| Parameter | Type | Description |
|---|---|---|
key |
string |
The variable’s key. |
value |
Color |
The color to assign. |
options? |
VariableOptions |
The layer to write. By default the active value set when it holds the key, else the default value. |
Returns#
void
Implementation of#
IVariableAPI.setColorSignature#
setColor(key: string, value: Color, options?: VariableOptions): voidgetColor()#
Get a color variable’s value.
Parameters#
| Parameter | Type | Description |
|---|---|---|
key |
string |
The variable’s key. |
options? |
VariableOptions |
The layer to read. By default the value that the scene shows. |
Returns#
ColorThe color value of the variable.
Implementation of#
IVariableAPI.getColorSignature#
getColor(key: string, options?: VariableOptions): ColorsetNumber()#
Set a number variable. Creates the variable if it doesn’t exist.
Every block property bound to the variable takes the number that the scene shows.
If a bound property rejects the value, the call throws its error, but the variable and the other bound
properties change anyway.
A new key must not be empty, start or end with whitespace, contain {{ or }}, or be reserved: scene_root and
keys that start with ubq..
{{ or }}, or be reserved: scene_root and
keys that start with ubq..Parameters#
| Parameter | Type | Description |
|---|---|---|
key |
string |
The variable’s key. |
value |
number |
The finite number to assign. |
options? |
VariableOptions |
The layer to write. By default the active value set when it holds the key, else the default value. |
Returns#
void
Implementation of#
IVariableAPI.setNumberSignature#
setNumber(key: string, value: number, options?: VariableOptions): voidgetNumber()#
Get a number variable’s value.
Parameters#
| Parameter | Type | Description |
|---|---|---|
key |
string |
The variable’s key. |
options? |
VariableOptions |
The layer to read. By default the value that the scene shows. |
Returns#
number
The number value of the variable.
Implementation of#
IVariableAPI.getNumberSignature#
getNumber(key: string, options?: VariableOptions): numbersetImage()#
Set an image variable. Creates the variable if it doesn’t exist.
Every block property bound to the variable takes the URI that the scene shows.
If a bound property rejects the value, the call throws its error, but the variable and the other bound
properties change anyway.
A new key must not be empty, start or end with whitespace, contain {{ or }}, or be reserved: scene_root and
keys that start with ubq..
{{ or }}, or be reserved: scene_root and
keys that start with ubq..Parameters#
| Parameter | Type | Description |
|---|---|---|
key |
string |
The variable’s key. |
uri |
string |
The URI of the image. |
options? |
VariableOptions |
The layer to write. By default the active value set when it holds the key, else the default value. |
Returns#
void
Implementation of#
IVariableAPI.setImageSignature#
setImage(key: string, uri: string, options?: VariableOptions): voidgetImage()#
Get an image variable’s URI.
Parameters#
| Parameter | Type | Description |
|---|---|---|
key |
string |
The variable’s key. |
options? |
VariableOptions |
The layer to read. By default the value that the scene shows. |
Returns#
string
The URI of the image.
Implementation of#
IVariableAPI.getImageSignature#
getImage(key: string, options?: VariableOptions): stringsetTypeface()#
Set a typeface variable. Creates the variable if it doesn’t exist.
Every text block whose typeface is bound to the variable takes the typeface that the scene shows, over its whole
text.
If a bound property rejects the value, the call throws its error, but the variable and the other bound
properties change anyway.
A new key must not be empty, start or end with whitespace, contain {{ or }}, or be reserved: scene_root and
keys that start with ubq..
{{ or }}, or be reserved: scene_root and
keys that start with ubq..Parameters#
| Parameter | Type | Description |
|---|---|---|
key |
string |
The variable’s key. |
typeface |
Typeface |
The typeface. It needs a name and at least one font. |
options? |
VariableOptions |
The layer to write. By default the active value set when it holds the key, else the default value. |
Returns#
void
Implementation of#
IVariableAPI.setTypefaceSignature#
setTypeface(key: string, typeface: Typeface, options?: VariableOptions): voidgetTypeface()#
Get a typeface variable’s value.
Parameters#
| Parameter | Type | Description |
|---|---|---|
key |
string |
The variable’s key. |
options? |
VariableOptions |
The layer to read. By default the value that the scene shows. |
Returns#
TypefaceThe typeface of the variable.
Implementation of#
IVariableAPI.getTypefaceSignature#
getTypeface(key: string, options?: VariableOptions): TypefacegetType()#
Get the type of a variable.
Parameters#
| Parameter | Type | Description |
|---|---|---|
key |
string |
The variable’s key. |
options? |
VariableOptions |
The layer to read. By default the value that the scene shows. |
Returns#
VariableTypeThe variable’s type.
Implementation of#
IVariableAPI.getTypeSignature#
getType(key: string, options?: VariableOptions): VariableTypefindAllOfType()#
Get the names of all variables of one type, of the scene or of the variables that wait for a scene. findAll
returns only text variables.
findAll
returns only text variables.Parameters#
| Parameter | Type | Description |
|---|---|---|
type |
VariableType |
The type of the variables. |
Returns#
string[]
List of variable names.
Implementation of#
IVariableAPI.findAllOfTypeSignature#
findAllOfType(type: VariableType): string[]