The Thymeleaf documentation states about sorting lists:
/*
* Sort a copy of the given list. The members of the list must implement
* comparable or you must define a comparator.
*/
${#lists.sort(list)}
${#lists.sort(list, comparator)}
In my document model, I have a list of maps with key value pairs (the published_content list from the JBake static page generator). In my template, I want to sort this list by comparing the value stored under a certain key in the maps.
In other words, the list variable has type List<Map<String, Object>> and I want to sort this list by comparing the value in each map stored under the key "mykey".
How can I formulate such a comparator in the template?
In Thymeleaf you need to use the full classname (include package). Something like: