Variables¶
Use variables to store and manipulate data within your templates. This includes assigning values, incrementing and decrementing numeric variables, and capturing output into a variable.
Functionality
- Assigning Variables: Stores a specific value in a variable.
- Incrementing Variables: Increases the value of a numeric variable by 1.
- Decrementing Variables: Decreases the value of a numeric variable by 1.
- Capturing Output: Captures the output of a block of code into a variable.
Syntax
Assigning Variables
You use the assign method to store values in a variable.
Use the increment method to increase a numeric variable by 1.
Use the decrement method to decrease a numeric variable by 1.
The capture method captures the rendered output of Liquid code into a variable.
These methods do not require any additional arguments.
Code Samples
Example 1: Assigning a Variable
Output: Example 2: Incrementing a Variable Output: Example 3: Decrementing a Variable Output: Example 4: Capturing Output into a Variable Output:Outliers¶
- Non-Numeric Increment/Decrement: Applying
incrementordecrementto non-numeric variables will not work as expected and may produce an error or unexpected results. - Reassigning Variables: Reassigning a variable will overwrite the old value with the new value.
- Scope Limitations: Variables assigned within a block may not be accessible outside of that block, depending on the scope.
Key Points¶
- Assignments are used for storing values into variables for later use within your Experience Builder pages.
- Increment and decrement methods are useful for counting or iterating within loops.
- Capture is ideal for creating complex strings or storing output from multiple Liquid statements.