Formatting numbers with liquid syntax
Overview
Ortto allows you to use Liquid template language in your email, SMS, and push notifications. In addition to formatting text, Liquid also supports basic math and logical operations, making it easy to calculate values, compare numbers, and control what content is shown to contacts.
By combining merge tags with Liquid math filters and conditional logic, you can create messages that adapt automatically such as calculating totals, enforcing limits, or displaying different content based on numeric values.
Learn more about personalizing campaign content with Liquid.
Performing basic math in Liquid
Liquid includes math filters that let you perform calculations directly inside your messages and action shapes. These are useful for totals, adjustments, scaling values, or simple calculations without external logic.
Description | Format | Example Output | Notes |
|---|---|---|---|
Add | {{ 16 | plus: 4 }} | 20 | Adds the second value to the first. |
Subtract | {{ 4 | minus: 2 }} | 2 | Subtracts the second value from the first. |
Multiply | {{ 3 | times: 2 }} | 6 | Multiplies two values. |
Divide | {{ 50 | divided_by: 1.5 }} | 33.33333333 | Returns a decimal when the divisor is a decimal. |
Rounding and number control
Liquid provides multiple ways to round numbers and keep values within a defined range. This helps prevent unexpected results and keeps values clean for display.
Description | Format | Example Output | Notes |
|---|---|---|---|
Round |
|
| Rounds to the nearest whole number or specified decimals. |
Ceiling (round up) |
|
| Always rounds up to the nearest whole number. |
Floor (round down) |
|
| Always rounds down to the nearest whole number. |
Maximum value |
|
| Caps the value at the specified maximum. |
Minimum value |
|
| Raises the value to the specified minimum if needed. |
Working with remainders and absolute values
Some calculations require working with remainders or ensuring values are always positive. You can use liquid filters to return these outputs.
Description | Format | Example Output | Notes |
|---|---|---|---|
Absolute value | {{ -12.68 | abs }} | 12.68 | Converts a number to a non-negative value. |
Modulo (remainder) | {{ 24 | modulo: 7 }} | 3 | Returns the remainder of a division operation. |
Comparisons and conditional logic
Liquid supports conditional statements and logical operators, allowing you to compare values and display different content depending on the result.
Description | Format | Example Output | Notes |
|---|---|---|---|
Compare three values |
|
| Evaluates multiple conditions using logical operators. |