IF/ELSE logic
Table of content:
Introduction
By using simple if/else statements, you can make your template automatically adapt to various user inputs.
Here is an example of a template using an if/else statement to invert the color theme based on a color selection input field:
In the example, the Color Selection input field is connected to the fill color property of the background rectangle. The fill color of the text object is also directly defined by the input field. However, the color of the rounded rectangles behind the text is defined by a simple IF/ELSE statement.
If the background is blue, the rectangles will be white; else, they will be blue.
Constructing an if/else expression
The IF/ELSE statement from the example above is implemented as an expression that looks like this:
rectangle2_fill = IF(EQUAL(rectangle1_fill, "#124BBAFF"), "#FFFFFFFF", "#124BBAFF")
The expression uses two logic functions: IF() and EQUAL().
The IF() function takes three arguments separated by commas, like this: IF(boolean_argument, value_if_true, value_if_false). The first argument must be a boolean value (true or false). The second value is the one that is returned by the IF() function if the first argument is true, and the third argument is the value that is returned if the first argument is false.
Usually, for the first argument, some sort of check is performed in the form of either a comparison function, such as EQUAL(), or by connecting the output value of a Checkbox input field.
In the example, the EQUAL() function was used, which takes two arguments and returns true if they are equal and false if they are not equal. This way, a check was constructed to see if the currently selected background-color is blue, and if so, the EQUAL() function returns true. This was then used to determine whether the rounded rectangles should be white or blue.