Filters
Filters transform values after they're resolved. They let you manipulate text, process arrays, format numbers, and much more. Filters are comma-separated and can be chained together for powerful data transformations.
String Filters
| Filter | Syntax | Description |
|---|---|---|
| Truncate | truncate N | Shorten to N characters, append ... |
| Replace | replace "X" with "Y" | Replace all occurrences of X with Y |
| URL Encode | url_encode | Percent-encode for use in URLs |
| Strip HTML | strip_html | Remove all HTML tags |
| Trim | trim | Remove leading and trailing whitespace |
| Newline to BR | newline_to_br | Convert line breaks to <br> tags |
| Split | split "sep" | Split a string into an array |
{the user's Bio, truncate 50}{the user's Code, replace "-" with " "}{the user's Email, url_encode}{the user's Bio, strip_html}{the user's Name, trim}{the user's Note, newline_to_br}{the user's Name, split " "}Array Filters
| Filter | Syntax | Description |
|---|---|---|
| Join | join "sep" | Join array elements with a separator |
| First | first | Get the first element |
| Last | last | Get the last element |
| Length | length or size | Count the number of elements |
| Sort | sort | Sort alphabetically (case-insensitive) |
| Reverse | reverse | Reverse the order |
| Unique | unique | Remove duplicates (preserves order) |
| Where | where "attr" is "val" | Filter list of objects by attribute value |
| Map | map "attr" | Extract one field from each object |
| Slice | slice N M | Get a sub-array from index N to M |
{the user's Tags, join ", "}{the user's Items, first}{the user's Items, last}{the user's Items, length}{the user's Tags, sort}{the user's Items, reverse}{the user's Tags, unique}{the user's Orders, where "status" is "active"}{the user's Orders, map "name"}{the user's Items, slice 0 3}Number Filters
| Filter | Syntax | Description |
|---|---|---|
| Round | round N | Round to N decimal places |
| Default | default "val" | Fallback on null, empty string, and zero |
{the user's Score, round 2}{the user's Name, default "Guest"}default vs or
The default filter and the or modifier behave differently:
or "value"triggers only when the data is null/missingdefault "value"triggers on null, empty string"", and zero0
Use or when you only want to replace missing values. Use default when you also want to replace empty strings and zeros.
| Scenario | or "Guest" | default "Guest" |
|---|---|---|
Value is null | Guest | Guest |
Value is "" (empty) | (empty) | Guest |
Value is 0 | 0 | Guest |
Value is "Jane" | Jane | Jane |
Chaining Filters
Filters apply left-to-right -- the output of each filter becomes the input for the next. This lets you build powerful transformation pipelines:
{the user's Bio, strip_html, truncate 100, trim}{the user's Orders, where "status" is "active", map "name", sort, join ", "}{the user's Name, split " ", first}{the user's Tags, unique, sort, join " | "}How Chaining Works (Step by Step)
Here's how {the user's Orders, where "status" is "active", map "name", sort, join ", "} is evaluated:
- Resolve
the user's Orders-- gets the full list of order objects where "status" is "active"-- filters to only orders with status "active"map "name"-- extracts just the name field from each ordersort-- sorts the names alphabeticallyjoin ", "-- combines them into a comma-separated string
When chaining filters, think about what type of data each filter expects. Array filters like sort and join need arrays as input. String filters like truncate need strings. The split filter converts a string to an array, and join converts an array back to a string.
Complete Filter Reference
| Filter | Syntax | Input Type | Output Type |
|---|---|---|---|
truncate | truncate N | String | String |
replace | replace "X" with "Y" | String | String |
url_encode | url_encode | String | String |
strip_html | strip_html | String | String |
trim | trim | String | String |
newline_to_br | newline_to_br | String | String |
split | split "sep" | String | Array |
join | join "sep" | Array | String |
first | first | Array | Any |
last | last | Array | Any |
length / size | length | Array/String | Number |
sort | sort | Array | Array |
reverse | reverse | Array | Array |
unique | unique | Array | Array |
where | where "attr" is "val" | Array | Array |
map | map "attr" | Array | Array |
slice | slice N M | Array | Array |
round | round N | Number | Number |
default | default "val" | Any | Any |