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.
FormatExampleOutput
{{truncate <string> <max_length> [replacement_suffix]}}How did you like your{{truncate product_name 5 "..."}}?How did you like your produ…?
 Note

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 the target to be changed.
  • replaceWith — The intended change to target if searchFor returns true.
  • limit — Optional. Replaces only the first X occurrences.
FormatExampleOutput
{{$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.
FormatExampleOutput
{{$split target delimiter index}}{{$split "a,b,c" ","}}
{{$split "a,b,c" "," 1}}
["a", "b", "c"]
["a", "b,c"]

Trim

$trim — Trims whitespace from both ends of a string.

Properties

  • target — The string to be trimmed.
FormatExampleOutput
{{$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 of target to point of replacement. Note index lengths are 0-indexed.
  • insertContent — The string or content to be inserted at the index point.
  • deleteCount — Optional. Deletes X characters from index.
FormatExampleOutput
{{$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.
FormatExampleOutput
{{$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.
FormatExampleOutput
{{$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.
FormatExampleOutput
{{$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.
FormatExampleOutput
{{$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.
FormatExampleOutput
{{$currencyFormat number locale=locale precision=precision}}{{$currencyFormat 100.129 locale="en-US"}}
{{$currencyFormat 120.999 locale="da-DK"}}
$ 100.13
€ 120,99