The ordinalize helper converts a number into its ordinal string form (e.g. 1 → 1st, 2 → 2nd, 3 → 3rd). It correctly handles special cases such as 11, 12, and 13, which use the th suffix rather than st, nd, or rd.
Syntax
{{ordinalize value}}
value -- The number to ordinalize. Required. Accepts integers and numeric strings. Does not work with negative numbers, floats, or non-numeric strings.
Examples
Ordinalize a set of numbers
{{ordinalize record.a}}
{{ordinalize record.b}}
{{ordinalize record.c}}
{{ordinalize record.d}}
{{ordinalize record.e}}
Input:
{ "record": { "a": 1, "b": 2, "c": 3, "d": 11, "e": 22 } }
Output:
1st 2nd 3rd 11th 22nd
11 uses th rather than st, demonstrating correct handling of the 11–13 special cases.
Ordinalize a single record field
{{ordinalize record.rank}}
Input:
{ "record": { "rank": 4 } }
Output: 4th
Usage notes
- Accepts integers and numeric strings (e.g.
"5"→5th). - Does not work with negative numbers, floats, or non-numeric strings.
- Numbers 11, 12, and 13 always use the
thsuffix regardless of their last digit.