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 thetarget
to be changed.replaceWith
— The intended change totarget
ifsearchFor
returns true.limit
— Optional. Replaces only the firstX
occurrences.
Format | Example | Output |
---|---|---|
{{$replace target searchFor replaceWith [limit=<number_expression>]}} | {{$replace "Some terrible jawn." "terrible" "cool"}} | Some cool jawn. |
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 oftarget
to point of replacement. Noteindex
lengths are 0-indexed.insertContent
— The string or content to be inserted at theindex
point.deleteCount
— Optional. DeletesX
characters 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 |
Categories