Products Downloads


French version


 

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:

  • "locale": string in IETF BCP 47 format identifying a sort locale,
  • "strength": string representing the strength of the collation to determine the level of difference considered as significant in the comparisons. Five values are provided: "identical", "primary", "secondary", "tertiary" and "quaternary".
  • "decomposition": string representing the collation decomposition mode. It determines the processing of Unicode combining characters. Setting the decomposition mode enables the user to choose between a quicker and fuller classification behavior. Three values are provided: "no_decomposition", "canonical_decomposition" and "full_decomposition"

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