This function returns a result sequence from sorting a sequence of scalar-type values (Boolean, Number, String, Date, Time or Date-time).
Sorting can be in ascending or descending order. The sequence must contain values of the same type.
When the sequence values are String type, locale-based sorting is applied.
Unlike lexicographic sorting which compares the coding value of each character, this sort uses a collation which enables two character strings to be compared according to a given language.
NB:
Some differences in relation to the FreeMarker "built-in" "sort" function (click here for more details) applied to a ([?]?sort) sequence and the "lexicographicSort" function:
- The result obtained from the three "sort", "lexicographicSort" and "localeBasedSort" functions is identical for Boolean/Number/Date/Time/Date-time types. For the String type, the Freemarker "sort" function applies a sort using a collation (so a result identical to "localBasedSort" but different from "lexicographicSort"),
- The "sort" function does not sort in descending order. The only solution is to use the FreeMarker "reverse" ([?]?sort_by?reverse) function, but the original order of equal values is not respected.
Parameters
Boolean/Number/String/Date/Time/Date-time sequence |
seqValues |
Sequence of values to sort |
Mandatory |
Boolean |
ascendingOrder |
"true" for an ascending sort, "false" for a descending sort |
Optional. The default value is "true" |
Hash |
collatorInfos |
Definition of collation information. This object can have the following attributes:
|
Optional. If this object is not provided, the locale taken for sorting is that entered for template execution ("strength" and "decomposition" attributes will have a default value which depends on the locale). |
For example
<#assign elegance = [ "Élégance", "Elegance", "elegance", "élégance", "elegANCE", "elègance" ]> <#-- Ascending sort --> <#list hardisCode.localeBasedSort(elegance, {'locale': 'fr_FR', 'strength':'primary'}) as aVal> - ${aVal} </#list>
The output is:
- Élégance
- Elegance
- elegance
- élégance
- elegANCE
- elègance
↑ Top of page