You can use text helpers to modify strings of text in Handlebars code. These helpers can be applied to the name of a data field or a literal value (placed in double quotes).
NOTE
Event data fields must come from the message's triggering event — it's not possible to reference past events from a user's event history with Handlebars.
# In this article
- Display the length of a string
- Check if two strings are equal
- Check if a string comes before another alphabetically
- Check if a string comes after another alphabetically
- Capitalize the first word of a string
- Capitalize all words
- Uppercase all letters
- Lowercase all letters
- Remove some text from a string
- Replace some text with other text
- Abbreviate
- Pad and center some text
- Turn a string into a URL slug
- Replace newlines
- Display a substring by index
- Want to learn more?
# Display the length of a string
The length helper displays the total number of characters (including spaces)
of the value of a data field.
# Properties
fieldName — The name of the user or event data field containing a string whose
length you want to display.
# Format
# Example
| Code | Example favoriteBook value | Output |
|---|---|---|
| To Kill A Mockingbird | 21 |
# Check if two strings are equal
The eq helper is generally used to check whether two numerical values are
equal, but it can also be used to check for an exact match between two strings.
If the two values are equal, it displays true. If the two values are not equal,
false is displayed. (Alphabetic order comparisons are case-sensitive.)
Keep in mind: If a merge tag using the eq or #eq helper references an empty
or missing field, the template will fail and the message will not be sent to
that user.
NOTE
To display content dynamically based on whether or not the eq helper evaluates
to true, use the #ifEq helper.
# Properties
fieldName1 — The name of the first user or event data field whose string value
you want to compare.
fieldName2 — The name of the second user or event data field whose string
value you want to compare.
# Format
handlebars
{{eq fieldName1 fieldName2}}
# Example
| Code | Example firstName value | Example preferredName value | Output |
|---|---|---|---|
| Elizabeth | Ellie | False |
# Check if a string comes before another alphabetically
The lt helper is generally used to compare two numerical values, but it can
also be used to check whether two strings are in alphabetical order. When used
this way, this helper checks to see whether the first letter of the first string
is "less" (comes earlier in the alphabet) than the first letter of the second
string. If the first value comes alphabetically after the second, it displays
true. If the first value comes alphabetically before the second, it displays
false. (Alphabetic order comparisons are case-sensitive.)
Keep in mind: If a merge tag using the lt or #lt helper references an empty
or missing field, the template will fail and the message will not be sent to
that user.
NOTE
To display content dynamically based on whether or not the lt helper evaluates
to true, use the #ifLt helper.
# Properties
fieldName1 — The name of the first user or event data field whose string value
you want to compare.
fieldName2 — The name of the second user or event data field whose string
value you want to compare.
# Format
handlebars
{{lt fieldName1 fieldName2}}
# Example
| Code | Example favoriteFruit value | Example favoriteAnimal value | Output |
|---|---|---|---|
| apple | zebra | true |
# Check if a string comes after another alphabetically
The gt helper is generally used to compare two numerical values, but it can
also be used to check whether two strings are in alphabetical order. When used
this way, this helper checks to see whether the first letter of the first string
is "greater" (comes later in the alphabet) than the first letter of the second
string. If the first value comes alphabetically after the second, it displays
true. If the first value comes alphabetically before the second, it displays
false. (Alphabetic order comparisons are case-sensitive.)
Keep in mind: If a merge tag using the gt or #gt helper references an empty
or missing field, the template will fail and the message will not be sent to
that user.
NOTE
To display content dynamically based on whether or not the gt helper evaluates
to true, use the #ifGt helper.
# Properties
fieldName1 — The name of the first user or event data field whose string value
you want to compare.
fieldName2 — The name of the second user or event data field whose string
value you want to compare.
# Format
handlebars
{{gt fieldName1 fieldName2}}
# Example
| Code | Example favoriteFruit value | Example favoriteAnimal value | Output |
|---|---|---|---|
| apple | zebra | false |
# Capitalize the first word of a string
The capitalizeFirst helper capitalizes the first word of a string.
# Properties
fieldName — The name of the user or event data field that contains the string
you want to capitalize.
# Format
# Example
| Code | Example favoriteFoods value | Output |
|---|---|---|
| blueberry scone | Blueberry scone |
# Capitalize all words
The capitalize helper capitalizes the first letter of each word in a string.
# Properties
fieldName — The name of the user or event data field that contains the string
you want to capitalize.
# Format
# Example
| Code | Example favoriteFoods.pastry value | Output |
|---|---|---|
| blueberry scone | Blueberry Scone |
# Uppercase all letters
The upper helper capitalizes every letter in a string.
# Properties
fieldName — The name of the user or event data field whose value should be
uppercased.
# Format
# Example
| Code | Example birthday.month value | Output |
|---|---|---|
| january | JANUARY |
# Lowercase all letters
The lower helper lowercases every letter in a string.
# Properties
fieldName — The name of the user or event data field whose value should be
lowercased.
# Format
# Example
| Code | Example brand value | Output |
|---|---|---|
| FItErAbLE | fiterable |
# Remove some text from a string
The cut helper removes all instances of a certain word, phrase, or character.
# Properties
fieldName — The name of the user or event data field containing the string to
be modified.
text — The text that should be cut from the string.
# Format
# Example
| Code | Example breakfastOrder value | Output |
|---|---|---|
| pancakes | cakes |
# Replace some text with other text
The replace helper finds and replaces all occurrences of one string with a
different string.
# Properties
fieldName — The field containing the string you want to search.
searchFor — The string within fieldName that you want to change.
replaceWith — The string that should replace all occurrences of searchFor.
# Format
# Example
| Code | Example timeOfYear value | Output |
|---|---|---|
| The dog days of summer | The cat days of summer |
# Abbreviate
The abbreviate helper shortens a string to a specified length and adds an
ellipsis (...).
NOTE
The three characters in the ellipsis count as part of the total length. Remember
to factor that in when you choose a value for length.
# Properties
fieldName — The user or event data field that contains the string you want
to abbreviate.
length — The total number of characters you want the string abbreviated to
(includes three characters for the ellipsis that's appended to the shortened
string).
# Format
# Example
| Code | Example iceCreamFlavor value | Output |
|---|---|---|
| chocolate | choc... |
# Pad and center some text
The center helper adds a series of specified characters to each side of a
word or phrase to add padding around the text and center it.
# Properties
fieldName — The user or event data field that contains the string you want
to pad and center.
# — The total number of characters you want the string to be, once the
padding characters have been added.
character — The character you want to add to each side of the string to pad it.
# Format
# Example
| Code | Example greeting value | Output |
|---|---|---|
| Hi there | ------Hi there------ |
# Turn a string into a URL slug
The slugify helper lowercases a string, removes non-word characters (numbers,
underscores, and apostrophes), strips leading and trailing spaces, and converts
spaces to hyphens.
# Properties
fieldName — The user or event data field that contains the string you want
to turn into a slug.
# Format
# Example
| Code | Example itemName value | Output |
|---|---|---|
| lil' café milk frother 2.0 | lil-café-milk-frother- |
# Replace newlines
The #breaklines block helper replaces \n or \r\n with <br>. This is
helpful for making sure newlines
display correctly in HTML.
# Properties
fieldName — The user or event data field that contains the string you want
to format with line breaks instead of newlines.
# Format
# Example
| Code | Example greeting value | Output |
|---|---|---|
| Hi there! Welcome to Fiterable. | Hi there! Welcome to Fiterable. |
# Display a substring by index
The substring helper displays part of a string, according to its position
within the containing string.
NOTE
The first character of the string has index 0.
# Properties
fieldName — The name of the field that contains the string (and substring)
you want to display.
index1 — The location within the string of the first character of the
substring you want to display.
index2 (optional) — The location within the string of the first character
after the end of the substring. (The character at this index is not included
in the output.)
# Format
# Example
| Code | Example brand value | Output |
|---|---|---|
| Fiterable | era |
# Want to learn more?
For more information about some of the topics in this article, check out these resources. Iterable Academy is open to everyone — you don't need to be an Iterable customer!
Iterable Academy
Support docs