Formatters are used to convert raw data into text that is easy to read. They are applied to data using a colon (:) and can be chained so that the output of each formatter becomes the input for the next. Some formatters support constant parameters or dynamic parameters.
The basic invocation of a formatter is as follows:
For example, in the case of converting the string "JOHN" to "John", the formatter lowerCase is used first to convert all letters to lower case, and then ucFirst is used to capitalize the first letter.
Data:
Template:
After rendering, the output is:
Many formatters support one or more constant parameters, which are separated by commas and enclosed in parentheses to modify the output. For example, :prepend(myPrefix) will add "myPrefix" in front of the text.
Note: If the parameter contains commas or spaces, it must be enclosed in single quotes, for example: prepend('my prefix').
Template example (see the specific formatter usage for details).
The output will have the specified prefix added in front of the text.
Formatters also support dynamic parameters. These parameters start with a dot (.) and are not enclosed in quotes.
There are two methods to specify dynamic parameters:
d. or c. (referring to root data or supplemental data)..), indicating that the property is looked up from the current parent object.For example:
It can also be written as a relative path:
If you need to access data from a higher level (parent or above), you can use multiple dots:
Data:
Usage in Template:
The examples yield 8, 8, 28, and 6 respectively.
Note: Using custom iterators or array filters as dynamic parameters is not allowed, for example: