A pipe |
allows for using the value of a variable to be the input value for a function. It is also possible to chain multiple functions together, so that the output of one function is used as input for the next one. Therefore a pipe can be used to modify the value of a variable in place. Several functions as well as basic mathematical operations can be used together with pipes.
Mathematical operations when using pipes are limited to elementary arithmetic: addition +
, subtraction-
, multiplication *
and division /
. The syntax looks like this:
@{ variable | +1 }
@{ variable | /2 | -5 | *2 }
Other variables can be used as well as operands. The following example will first set variable
to the value of x
if not defined. In a second step, the value of y
or a default of 5
is added:
@{ variable | def (@{ x }) | +@{ y | def (5) } }
The syntax for functions looks as follows:
@{ text | markdown }
Paramters can be passed to functions optionally:
@{ text | markdown (true) }
Those function parameters can be numbers, strings, boolean or even other variables. As you can see below, pipe functions can also be used for such nested variables:
@{ date | dateFormat (@{ format | def ('Y') }) }
There is also a special shorthand syntax for shortening text variables. The following example shortens the value of a variable to 100 characters whithout cutting words:
@{ text | 100 }
The following example will first strip all markdown and HTML tags from the textTeaser
variable and then shorten the text to 150 characters:
@{ textTeaser | stripTags | 150 }
Note that single quotes as well as double quotes can be used to wrap strings. Both examples below will produce the same output:
<# Output: This is a "Test String" #>
@{ text | def ('This is a "@{ variable }"') }
@{ text | def ("This is a \"@{ variable }\"") }
Variables used as function parameters only need to be quoted when being combined with strings. In case you just want to use a variable, quotes can be omitted:
@{ text | def (@{ variable }) }