Operations can be applied to the data source property that contains an array of objects. It allows processing the data before putting them into the template.
The operation returns an array of the objects that meet a condition and assign them to a token initiated with alias.
Syntax:
{{filteredObjects = objects|filter(value.objectProperty != false)}}
Available operators:
==
equal to,
!=
not equal to,
>
more than,
<
less than,
>=
more than or equal to,
<=
less than or equal to,
||
logical “or”,
&&
logical “and”,
()
group.
The operation sorts items in the array of objects and may be used either separately or with alias.
Syntax
Usage with the alias:
{{sorted = items|sort(property, DESC)}}
{{sorted.property}}
Separate usage:
{{items|sort(property).property}}
{{items|sort(property1, ASC).property2}}
Sorting parameters
ASC
ascending order (applied by default, may be skipped),
DESC
descending order.
Template |
Data |
Result |
---|---|---|
{{sorted = customers|sort(lastName, ASC)}}
Customers:
- {{sorted.lastName}}, {{sorted.firstName}}
|
{
"customers": [
{
"firstName": "Adele",
"lastName": "Vance"
},
{
"firstName": "Diego",
"lastName": "Siciliani"
},
{
"firstName": "Johanna",
"lastName": "Lorenz"
}
]
}
|
Customers:
- Lorenz, Johanna
- Siciliani, Diego
- Vance, Adele
|
The operation returns a specified number of the top objects from the array and assign them to a token initiated with alias.
Syntax:
{{topObjects = objects|top(3)}}
The operation returns a certain object from the array by its index and assign it to a token initiated with alias.
Syntax:
{{atObject = objects|at(2)}}
The operation returns a portion of an array of objects from the start index to the end index (the object at the end index is not included). The array portion is then assigned to a token initiated with alias. Indexes are zero-based. The end index is optional.
Syntax:
{{slicedObjects = objects|slice(1, 3)}}
Available operators:
Template |
Data |
Result |
---|---|---|
{{slicedNumbers = numbers|slice(1, 3)}} Sliced numbers:
|
{
"numbers": [
{
"name": "zero"
},
{
"name": "one"
},
{
"name": "two"
},
{
"name": "three"
},
{
"name": "four"
}
]
}
|
Sliced numbers:
|
{{slicedNumbers = numbers|slice(2)}} Sliced numbers:
|
{
"numbers": [
{
"name": "zero"
},
{
"name": "one"
},
{
"name": "two"
},
{
"name": "three"
},
{
"name": "four"
}
]
}
|
Sliced numbers:
|