Text helpers
Text helpers transform text content in Handlebars expressions.
Limit string length (Truncate)
truncate — Limits string length.
Properties
string— The string, string variable, or expression that produces a string whose length you want to limit.max_length— An integer representing the maximum string length.replacement_suffix— An optional string you want to append to the end of the truncated string if, and only if, Airship truncates the string.
| Format | Example | Output |
|---|---|---|
{{truncate <string> <max_length> [replacement_suffix]}} |
How did you like your{{truncate product_name 5 "..."}}? |
How did you like your produ…? |
The max_length includes the replacement suffix, so if you set a max_length of 8, and a replacement_suffix with 3 characters (e.g. ...), Airship will only display 5 characters from a truncated string; the remaining 3 characters of any truncated string are consumed by the replacement_suffix.
For example, if you have an attribute ID name with value yourname, {{truncate name 7 "---"}} would resolve to your---. Without the suffix, the same property would truncate to yournam.
Replace
$replace — Replaces all occurrences of searchFor with replaceWith in string target.
Properties
target— The string or user-specific variable to be searched.searchFor— A string within thetargetto be changed.replaceWith— The intended change totargetifsearchForreturns true.limit— Optional. Replaces only the firstXoccurrences.
| Format | Example | Output |
|---|---|---|
{{$replace target searchFor replaceWith [limit=<number_expression>]}} |
{{$replace "Some terrible jawn." "terrible" "cool"}} |
Some cool jawn. |
Split
$split — Splits a string target on a given string delimiter, returning an array of strings split on the characters in delimiter. You may also specify a limit to only split a string a maximum number of times.
Properties
target— The string to be split.delimiter— The characters on which to split.limit— The maximum number of splits to perform.
| Format | Example | Output |
|---|---|---|
{{$split target delimiter index}} |
{{$split "a,b,c" ","}} {{$split "a,b,c" "," 1}} |
["a", "b", "c"] ["a", "b,c"] |
Join
$join — Joins an array target using a given string delimeter, outputting a single string.
Properties
target— The array to be joined. An error will be thrown if this parameter is any type other than an array.delimeter— A string to insert between the elements in thetargetarray.
| Format | Example | Output |
|---|---|---|
{{$join target delimeter}} |
{{$join ($array "red" "green" "blue") "-"}} {{$join ($array 1 2 3) ", "}} |
red-green-blue 1, 2, 3 |
Trim
$trim — Trims whitespace from both ends of a string.
Properties
target— The string to be trimmed.
| Format | Example | Output |
|---|---|---|
{{$trim target}} |
{{$trim " abc "}} |
abc |
Splice
$splice — Inserts string insertContent into string target at index index.
Properties
target— The string or user-specific variable to be searched.index— The count from start oftargetto point of replacement. Noteindexlengths are 0-indexed.insertContent— The string or content to be inserted at theindexpoint.deleteCount— Optional. DeletesXcharacters fromindex.
| Format | Example | Output |
|---|---|---|
{{$splice target index insertContent deleteCount=X}} |
{{$splice "xxxzzz" 3 "yyy"}} {{$splice "xxxzzz" 1 "y" deleteCount=4}} |
xxxyyyzzz xyz |
Capitalize
$capitalize — Capitalizes the first letter of a given string.
Properties
string— The string or user-specific variable to capitalize.locale— Optional. An IETF BCP 47 language tag.
| Format | Example | Output |
|---|---|---|
{{$capitalize string locale=DEFAULT}} |
{{$capitalize "word"}} |
Word |
Uppercase
$uppercase — Converts a given string to uppercase.
Properties
string— The string or user-specific variable to uppercase.locale— Optional. An IETF BCP 47 language tag.
| Format | Example | Output |
|---|---|---|
{{$uppercase string locale=DEFAULT}} |
{{$uppercase "word"}} |
WORD |
Lowercase
$lowercase — Converts a given string to lowercase.
Properties
string— The string or user-specific variable to lowercase.locale— Optional. An IETF BCP 47 language tag.
| Format | Example | Output |
|---|---|---|
{{$lowercase string locale=DEFAULT}} |
{{$lowercase "Word"}} |
word |
Format number
$numberFormat — Converts a number to a given locale and precision.
Properties
number— The number to be formatted.locale— An IETF BCP 47 language tag, e.g.,en-US.precision— Optional. An integer specifying the maximum number of decimal places that should be shown.
| Format | Example | Output |
|---|---|---|
{{$numberFormat number locale=locale precision=precision}} |
{{$numberFormat 100000 locale="en-US" }} {{$numberFormat 100000.012 locale="en-US" precision=2}} {{$numberFormat 1000 locale="da-DK" precision=2}} |
100,000 100,000.01 1.000,00 |
Format currency
$currencyformat — Converts a number into a currency representation for the given locale and precision.
Properties
number— The number to be formatted.locale— An IETF BCP 47 language tag, e.g.,en-US.precision— Optional. An integer specifying the maximum number of decimal places that should be shown.
| Format | Example | Output |
|---|---|---|
{{$currencyFormat number locale=locale precision=precision}} |
{{$currencyFormat 100.129 locale="en-US"}} {{$currencyFormat 120.999 locale="da-DK"}} |
$ 100.13 € 120,99 |
Categories