Pipes - Transform Output with Functions
Pipes allow you to pass output through functions to transform it. Use the pipe symbol | followed by a function name to process data.
Two Ways to Use Pipes
1. Variable Pipes
Apply functions to variables using {echo $variable | function}:
2. Tag Pipes
Apply functions to tag output. Pipes can be placed on the opening tag or closing tag:
Pipe Timing: Opening vs Closing Tag
The placement of the pipe determines when the function is applied:
-
Opening tag
{tag | function} - Processes data BEFORE the tag content is rendered
-
Closing tag
{/tag | function} - Processes output AFTER the tag is finished
Chaining Pipes
Chain multiple pipe functions together by separating them with |. Functions are applied left to right:
Common Pipe Functions
|
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')}
|
Important Rules
-
Use {echo} with variables -
{echo $var | function} NOT {$var | function}
-
Arithmetic needs spaces -
{echo $x | + 1} NOT {echo $x | +1}
-
Quote string parameters -
{echo $x | replace('a','b')}
-
Functions apply left to right -
{echo $x | trim | upper} trims first, then uppercases
When to Use Opening vs Closing Tag Pipes
|
Use Case
|
Placement
|
Example
|
|
Transform input data before processing
|
Opening tag
|
{items | sort}...{/items}
|
|
Transform final output after rendering
|
Closing tag
|
{tag}...{/tag | upper}
|
|
Format variable values
|
Variable pipe
|
{echo $price | number_format(2)}
|
See Also
-
{echo} - Evaluate and output expressions
-
{functions} - List of all pipe functions
-
{options} - Tag options reference