Overview
Formulas allow you to execute JavaScript expressions within your templates to perform calculations, transformations, and complex logic.Formula Syntax
Formulas are enclosed in{{% %}} and must start with return:
All formula expressions must begin with the
return keyword.Basic Calculations
Perform arithmetic operations on your data:Example: Simple Calculation
Financial Calculations
Formulas are perfect for computing taxes, totals, and other financial values:VAT and Total Calculation
String Operations
Manipulate strings using JavaScript string methods:- Length
- Uppercase
- Lowercase
- Substring
- Replace
Date and Time
The now Variable
Access the current date and time using the implicit now variable:
Date Methods
- ISO String
- Date String
- Year
- Month
2024-06-15T10:30:00.000ZNumber Formatting
Use JavaScript number methods for precise formatting:Common Number Methods
- Fixed Decimals
- Precision
- Exponential
123.46Array Operations
Work with arrays using JavaScript array methods:- Length
- Join
- First Item
- Last Item
Conditional Expressions
Use ternary operators for inline conditionals:Examples
- Status Display
- Discount Badge
- Quantity Label
Complex Calculations
Combine multiple operations for sophisticated logic:Multi-tier Discount Calculation
Percentage Calculation
Duration Calculation
Mathematical Operations
Use theMath object for advanced calculations:
- Rounding
- Min/Max
- Power/Root
- Absolute
Best Practices
Always use return keyword
Always use return keyword
Formula expressions must start with
return:Format calculated numbers
Format calculated numbers
Use
.toFixed() for consistent decimal places:Handle undefined values
Handle undefined values
Check for undefined before calculations:
Keep formulas readable
Keep formulas readable
Break complex calculations into multiple formulas:
Related Topics
Variables
Learn about variable syntax and formatting
Conditionals
Use formulas in conditional expressions
Lists
Apply formulas within list iterations