Operators¶
Experience Builder's Liquid supports a wide range of operators, allowing for advanced functions and calculations within Liquid resources. List of Operators
-
Arithmetic Operators
- Addition (
+) - Subtraction (
-) - Multiplication (
*) - Division (
/) - Modulus (
%) - Floor (
floor) - Ceil (
ceil)
- Addition (
-
Logical Operators
-
Comparison Operators
- Equal (
==) - Not Equal (
!=) - Greater Than (
>) - Less Than (
<) - Greater Than or Equal (
>=) - Less Than or Equal (
<=) - Contains (
contains)
- Equal (
-
String Operators
Arithmetic Operators¶
Addition (+)¶
- Syntax:
left + right - Adds two numbers.
Example:
Output: Key Points:- Works with
Numbervalues. - Implicit conversion may occur when dealing with
Stringvalues.
Subtraction (-)¶
- Syntax:
left - right - Subtracts the right number from the left.
Example:
Output: Key Points:- Ensure both operands can be converted to
Numbervalues.
Multiplication (*)¶
- Syntax:
left * right - Multiplies two numbers.
Example:
Output: Key Points:- Use
NumberValuefor operations requiring precision.
Division (/)¶
- Syntax:
left / right - Divides the left number by the right.
Example:
Output: Special Cases:- Division by zero returns
Nilvalue.
Modulus (%)¶
- Syntax:
left % right - Returns remainder of the division.
Example:
Output: Special Cases:- Only applicable if both operands are integers.
Floor¶
- Syntax:
{{ [value] | floor }} - Rounds down to the nearest integer.
Example:
Output:Ceil¶
- Syntax:
{{ [value] | ceil }} - Rounds up to the nearest integer.
Example:
Output:Logical Operators¶
And¶
- Syntax:
[value1] and [value2] - Logical AND operation.
Example:
Output:Or¶
- Syntax:
left or right - Logical OR operation.
Example:
Output:Result: true
Not¶
- Syntax:
not value - Logical NOT operation.
Example:
Output: Special Cases:- Works with any
Booleanvalue.
Comparison Operators¶
Equal¶
- Syntax:
left == right - Checks if values are equal.
Example:
Output:Not Equal¶
- Syntax:
left != right - Checks if values are not equal.
Example:
Output:Greater Than¶
- Syntax:
left > right - Checks if left value is greater than right value.
Example:
Output:Less Than¶
- Syntax:
left < right - Checks if left value is less than right value.
Example:
Output:Greater Than or Equal¶
- Syntax:
left >= right - Checks if left value is greater than or equal to right value.
Example:
Output:Less Than or Equal¶
- Syntax:
left <= right - Checks if left value is less than or equal to right value.
Example:
Output:Contains¶
- Syntax:
left contains right - Checks if left value contains the right value.
Example:
Output: Special Cases:- Works with strings and arrays only.
String Operators¶
Append¶
- Syntax:
left | append: right - Appends the right string to the left string.
Example:
Output:Prepend¶
- Syntax:
left | prepend: right - Prepends the right string to the left string.
Example:
Output:Slice¶
- Syntax:
slice(value, offset, length) - Extracts substring from the specified offset with an optional length.
Example:
Output:Remove¶
- Syntax:
remove(value, substring) - Removes the first instance of substring.
Example:
Output:Replace¶
- Syntax:
replace(value, old, new) - Replaces all instances of old with new.
Example:
Output:Key Points¶
Implicit Conversions¶
It's crucial to note that implicit conversions can occur, especially when adding numbers and strings. For instance, adding a String and Number could lead the result to default to a String.
Nil and Null¶
Operations involving Nil usually return Nil, particularly in division and comparison.
Boolean Context¶
In conditional statements, Empty, Blank, and False behave similarly by returning a False context.