Pipes allow you to pass output through functions to transform it. Use the pipe symbol | followed by a function name to process data.
Apply functions to a variable with {$variable | function} - the field tag runs the sanitize chain on the result - or with {echo $variable | function}, which prints it raw, as the examples on this page do:
|
PHP fragments/pipes_1.php |
HTML fragments/pipes_1.pad |
Result |
|---|---|---|
|
|
Original: john doe Uppercase: JOHN DOE Capitalize: John Doe Original: ALICE@EXAMPLE.COM Lowercase: alice@example.com Original: 1234.56 Formatted: 1,234.56 |
Apply functions to tag output. Pipes can be placed on the opening tag or closing tag:
|
PHP fragments/pipes_2.php |
HTML fragments/pipes_2.pad |
Result |
|---|---|---|
|
|
Items separated by commas: apple, banana, cherry Items in uppercase:
|
The placement of the pipe determines when the function is applied:
{tag | function} - transforms the content template, once, before any occurrence is rendered. What the function is handed is the source between the tags, not the tag's data.{/tag | function} - transforms the output, after every occurrence has been rendered and joined.An opening pipe is therefore not a way to reorder or filter what a tag iterates: a field written inside the content would be transformed along with everything else, and then not resolve. Reshaping the data is what the data handling options are for.
|
PHP |
HTML fragments/pipes_4.pad |
Result |
|---|---|---|
|
Closing tag pipe - handed everything the tag rendered: [ALPHA BETA ] Opening tag pipe - handed the content template, which then repeats: [ROW ROW ] |
Chain multiple pipe functions together by separating them with |. Functions are applied left to right:
|
PHP fragments/pipes_3.php |
HTML fragments/pipes_3.pad |
Result |
|---|---|---|
|
|
Chain multiple pipes together: Original: [ hello world ] Trimmed and uppercase: [HELLO WORLD] Original: the quick brown fox Uppercase first letter of each word: The Quick Brown Fox Replace and capitalize each word: The Quick Brown Dog |
truncate shortens on a whole word, slug makes a readable URL part,
bytes writes a size for people, and escape writes a value for the
context it lands in - html, attr, js, css or
url:
|
PHP fragments/pipes_5.php |
HTML fragments/pipes_5.pad |
Result |
|---|---|---|
|
|
The quick brown fox jumps… ?page=creme-brulee-co 3 GB it\x27s\x20\x3C\x2Fscript\x3E |
| Function | Description | Example |
|---|---|---|
upper |
Convert to uppercase | {echo $text | upper} |
lower |
Convert to lowercase | {echo $text | lower} |
ucwords |
Capitalize each word | {echo $text | ucwords} |
trim |
Remove whitespace | {echo $text | trim} |
html |
HTML encode | {echo $text | html} |
replace(a,b) |
Replace text | {echo $text | replace('old','new')} |
+ n |
Add number | {echo $count | + 1} |
date(fmt) |
Format date | {echo $timestamp | date('Y-m-d')} |
{echo 'text' | upper}; a field pipes as it stands, {$var | upper}, as well as through {echo $var | upper} - which prints the value raw, without the sanitize chain the field tag runs{echo $x | + 1} NOT {echo $x | +1}{echo $x | replace('a','b')}{echo $x | trim | upper} trims first, then uppercases| Use Case | Placement | Example |
|---|---|---|
| Transform the content template before it repeats | Opening tag | {items | trim}...{/items} |
| Reshape the data itself | Option, not a pipe | {items sort}...{/items} |
| Transform final output after rendering | Closing tag | {tag}...{/tag | upper} |
| Format variable values | Variable pipe | {echo $price | number_format(@, 2)} |