This repository has been archived by the owner on Oct 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
6. Filters
Whilein edited this page May 22, 2021
·
3 revisions
Some expressions inside values, conditions or loops may be filtered, for example you may to sort an array or list inside the template, using ":sorted" filter:
{% for element : unsorted_array:sorted %}
{{ element }}
{% endfor %}
There are many other filters, see the following table:
Name | Description | Applicables to | Output |
---|---|---|---|
:average | Get average number of numeric array or collection | Any numerical array or collection of numbers | double |
:capitalize | Set first character to uppercase | String | String |
:byte, :short, :int and etc | Cast to primitive | Any object | Any primitive |
:ceil | Math.ceil | Any number | double |
:floor | Math.floor | Any number | double |
:round | Math.round | Any number |
double if applies to double, else float
|
:escapetags | Escapes xml/html tags | String | String |
:striptags | Removes xml/html tags | String | String |
:trim | Removes spaces from start and end of string | String | String |
:lower | String.toLowerCase | String | String |
:upper | String.toUpperCase | String | String |
:tostr | Arrays.toString | Any array | String |
:hex | String to hex | String or byte[] | String |
:sorted | Sort an array | Any array or collection of Comparable<T>
|
That collection or array |
:shuffle | Shuffle an array | Any array or collection | That collection or array |
:wrap | Cast primitive to wrapper, e.g int -> Integer | Any primitive | Wrapper |
:sum | Get sum of array/collection elements | Any array or collection of numbers |
int if array and component type is byte, short or int, else double
|
:max | Get max element of array/collection | Any array or collection of Comparable<T>
|
T |
:min | Get min element of array/collection | Any array or collection of Comparable<T>
|
T |
See filter implementations: Click me
You can set filters to parentheses, strings, numbers or values, i.e. (1 + 1):<filter>
, "":<filter>
, 1:<filter>
or name:<filter>
.
If you want to specify multiple filters just use value:<filter1>:<filter2>:<filter3>
Also you can add your own filters if you want, just use Te4j.getFilters().add(Filter)
.