With the `sort` modifier, you can sort a list of data based on a specific column within the list. Additionally, you can specify whether the sorting should be in ascending (asc) or descending (desc) order.
With the `sort` modifier, you can sort a list of data based on a specific column within the list. Additionally, you can specify whether the sorting should be in ascending (asc) or descending (desc) order.
Sort
{{$array|sort:'product_id':'<asc/desc>'}}
Sort products
The following product structure is available:
{ "producten": [
{ "productid": 22 "name": "Slippers" },
{ "productid": 5, "name": "Socks" },
{ "productid": 3, "name": "Shoes" }
] }
By sorting based on the product ID, the products are sorted in ascending order.
{{foreach $products|sort:'product_id':'asc' item=product}}
{{$product.productid}}: {{$product.name}}
{{/foreach}}
Output:
3: Shoes
5: Socks
22: Slippers