In the template editor, a variable connects an input field with your design. A variable is a value with a name: the input field writes what users enter in the design generator into it, and properties and expressions read the value by its name.
Where variables come from
Every input field except an input field group and an instruction stores its value in a variable. Its name is the input field's Variable name setting. Bluepic builds it from the field type or the element, for example text2_text. You can rename it, see Input field settings.
Users only see the input field, not the variable.
Bluepic also brings a few variables of its own, for example TIME, the current time of an animation.
Use variables in expressions
To use a variable, write its name in an expression. If the variable is called price, for example, price * 1.19 gives the price plus 19 %. In a text, you insert it with ${price}. The details are in Expression syntax.
When users change the input field, every property whose expression uses the variable changes with it.
In the expression editor, the Variables tab lists every variable you can use in the property you are editing.
One input field for several properties
Every new input field gets its own variable. To let an input field control more properties, also in other elements, enter its variable name there as the expression. The easiest way is the property's expression editor. How to open it is explained in Use the expression editor. Click the block in the expression editor, then the variable name in the Variables tab, for example brandColor, and finally Update.
After that, the property is connected to the input field just like the first one: it is highlighted in the properties panel, and when you hover over it, it shows Edit Field and Delete Field. This way users can, for example, change several shapes with one color. Delete Field then deletes the input field for all of these properties, though, not just for one.
What happens when you rename or delete
- When you rename a variable, every expression that uses it takes over the new name automatically.
- When you delete an input field, you delete its variable too. Every property and every expression that used the variable keeps its last value as a fixed value. More on this in Delete an input field.
Clean up unused variables
Variables that no input field, element or expression uses anymore can be removed all at once in the Input Fields view.
- Click Input Fields at the top right of the toolbar. The Input Fields view opens.
- Select at least one input field with its checkbox. Only then does the menu with the three vertical dots open. The selected input field stays.
- Click the three vertical dots next to Delete at the top and then Clean up unused variables (n). The number shows how many unused variables there are. Studio removes them right away. If the entry is greyed out, there are none.
- Click × at the top right to close the Input Fields view.
Unique names
In an expression, a name can mean a variable or an element. That is why a variable and an element in the layers panel can't have the same name.