Expressions in [[ ... ]], data-condition, data-ef-text, and similar attributes can call built-in functions. You can also register custom functions with registerTemplateFunction(name, fn) or registerTemplateFunctions({ name: fn, ... }).
Most checkout and cart values are already formatted (e.g. "$29.00"). Use them directly in [[ ... ]]. Use formatPrice() only when you need to display a raw number (e.g. *_raw keys or a computed number).
Do not pass an already-formatted string into formatPrice (e.g. formatPrice(checkout.total, ...) or formatPrice(item.price, ...)). That can produce wrong or duplicated currency symbols.
Formats a numeric value as currency.
| Parameter | Description |
|---|
| value | Number (or parseable to number) |
| currency | Optional. Code (e.g. USD) or symbol. If omitted, uses checkout.currency or scope.currency or USD. |
| locale | Optional. For Intl.NumberFormat. |
Cart helpers
| Function | Returns | Example |
|---|
lineTotal(item, quantityKey?, priceKey?) | quantity × price for one item (default keys: quantity, price) | [[ formatPrice(lineTotal(item), currency) ]] when item.total is not in scope |
cartCount(items) / cart_count(items) | Sum of item quantities | [[ cartCount(cartItems) ]] |
cartSubtotal(items, quantityKey?, priceKey?) / cart_subtotal(...) | Numeric sum of line totals | [[ formatPrice(cartSubtotal(cartItems), checkout.currency) ]] |
String helpers
All coerce to string; null/undefined become empty string.
| Function | Description | Example result |
|---|
upper / uppercase | Uppercase | ”ALPHA” |
lower / lowercase | Lowercase | ”alpha” |
capitalize | First character uppercase | ”Alpha” |
titleCase / title | Title case | ”Product Alpha” |
camelCase / camel | camelCase | ”someLabel” |
snakeCase / snake | snake_case | ”some_label” |
kebabCase / kebab | kebab-case | ”some-label” |
Custom functions
Register from application or plugin code:
import { registerTemplateFunction, registerTemplateFunctions } from './utils/templateProcessor.js';
registerTemplateFunction('myFormat', (value) => {
return value != null ? String(value).toUpperCase() : '';
});
registerTemplateFunctions({
double: (n) => Number(n) * 2,
greet: (name) => `Hello, ${name || 'Guest'}!`
});
Then in templates: [[ myFormat(item.name) ]], [[ double(item.quantity) ]], [[ greet(checkout.customer.first_name) ]].
Summary
- Price display: Use the table above: pre-formatted keys as-is; formatPrice only for raw values or computed numbers.
- Cart:
cartCount, cartSubtotal, lineTotal; combine with formatPrice when you need a formatted string from a number.
- Strings:
upper, lower, capitalize, titleCase, camelCase, snakeCase, kebabCase (and aliases).
- Custom:
registerTemplateFunction / registerTemplateFunctions.
Next: Cart and Checkout.