Formatting text with liquid syntax
Overview
Ortto allows you to use Liquid template language in your email, SMS, and push notifications. This gives you powerful tools to format text, clean up data, and adjust values dynamically before they’re shown to contacts.
By combining merge tags with Liquid filters, you can standardize names, format numbers and phone fields, safely display HTML, and build cleaner, more personalized messages without manual edits.
Learn more about personalizing campaign content with Liquid.
Working with text formatting
Liquid includes a wide range of text filters that help you control how content appears. You can adjust capitalization, add or remove text, shorten long strings, or normalize inconsistent data.
Common examples include:
- Capitalizing or uppercasing names
- Appending domains or email suffixes
- Truncating long text for previews
- Removing extra whitespace or line breaks
These filters are especially useful when contact data is inconsistent or user-generated.
Description | Format | Example Output | Notes |
|---|---|---|---|
Prepend text | {{ people.custom.domain | prepend: "https://www." }} | Adds the string to the start of the value. | |
Append text | {{ people.first-name | append: "@email.com" }} | lauren@email.com | Adds the string to the end of the value. |
Capitalize | {{ people.first-name | capitalize }} | Jerry | Uppercases the first character and lowercases the rest. |
Lowercase | {{ "Jerry" | downcase }} | jerry | Converts all characters to lowercase. |
Uppercase | {{ "Jerry" | upcase }} | JERRY | Converts all characters to uppercase. |
Normalize name | {{ people.first-name | downcase | capitalize }} | Ortto | Fixes names in all caps or all lowercase. |
Reverse | {{ ".ottrO morf olleH" | split: "" | reverse | join: "" }} | Hello from Ortto | Reverses characters or array order. |
Truncate text | {{ "Hello from Ortto!" | truncate: 9 }} | Hello ... | Limits characters and adds ellipsis. |
Truncate words | {{ "Hello from Ortto!" | truncatewords: 1 }} | Hello ... | Limits word count and adds ellipsis. |
Cleaning and transforming data
You can use Liquid to clean up strings and arrays before displaying them. This includes removing unwanted characters, deduplicating lists, and stripping HTML or newlines from content.
Common use cases include:
- Removing duplicate values from a list
- Stripping HTML tags from text fields
- Removing specific words or characters
These transformations help ensure your messages stay readable and correctly formatted across channels.
Description | Format | Example Output | Notes |
|---|---|---|---|
Remove all matches | {{ "Customer journeys made remarkable" | remove: "ma" }} | Customer journeys de rerkable | Removes every occurrence of the text. |
Remove first match | {{ "Customer journeys made remarkable" | remove_first: "ma" }} | Customer journeys de remarkable | Removes only the first occurrence. |
Replace all | {{ "An update on my order" | replace: "my", "your" }} | An update on your order | Replaces every matching string. |
Replace first | {{ "My order and my total" | replace_first: "my", "your" }} | Your order and my total | Replaces only the first match. |
Strip HTML | {{ "Have you signed up?" | strip_html }} | Have you signed up? | Removes all HTML tags. |
Escape HTML | {{ " Content " | escape }} | <div>Content</div> | Escapes HTML so it displays as text. |
Escape once | {{ " Content " | escape_once }} | <div>Content</div> | Prevents double-escaping existing entities. |
Remove newlines | {{ "Line 1\nLine 2" | strip_newlines }} | Line 1Line 2 | Deletes all line breaks. |
Newlines to <br> | {{ "Line 1\nLine 2" | newline_to_br }} | Line 1<br />Line 2 | Converts line breaks to HTML <br />. |
Whitespace control
This table shows how to remove unwanted whitespace from text or field values.
Description | Format | Example Output | Notes |
|---|---|---|---|
Trim both sides | {{ " Hello " | strip }} | Hello | Removes whitespace from both sides. |
Trim left | {{ " Hello " | lstrip }} | "Hello " | Removes whitespace from the left side only. |
Trim right | {{ " Hello " | rstrip }} | " Hello" | Removes whitespace from the right side only. |
Working with arrays and lists
Liquid can be used to work with arrays created from strings or existing fields. You can split strings into arrays, select the first or last item, remove duplicates, and join values back together with custom separators.
This is helpful when:
- Displaying lists of locations, products, or tags
- Selecting a single value from a longer list
- Reformatting comma-separated data into readable text
Description | Format | Example Output | Notes |
|---|---|---|---|
Split | {% assign varcities = "London, New York, Milan" | split: ", " %} {% for item in varcities %} {{ item }} {% endfor %} | London New York Milan | Splits a string into an array. |
Join array | {% assign varcities = "London, New York" | split: ", " %} {{ varcities | join: " and " }} | London and New York | Combines array values using a separator. |
First item | {{ "Hello from Ortto" | split: " " | first }} | Hello | Returns the first array item or character. |
Last item | {{ "Hello from Ortto" | split: " " | last }} | Ortto | Returns the last array item or character. |
Remove duplicates | {% assign varMy_Products = "hats, scarves, scarves, shoes" | split: ", " %} {{ varMy_Products | uniq | join: ", " }} | hats, scarves, shoes | Deduplicates array values. |
Compact array | {{ array | compact }} | [1, "apple", true] | Removes nil values and returns a new array. |
Safe handling of HTML and URLs
When working with content that may include HTML or special characters, Liquid provides filters to safely escape or clean the output. You can escape HTML so it displays as text, remove tags entirely, or encode and decode URLs as needed.
This is useful when:
- Preventing broken layouts caused by HTML
- Passing values safely through URLs
Description | Format | Example Output | Notes |
|---|---|---|---|
MD5 hash | {{ "email" | md5 }} | 7f2cb18d2b4f7a8f65b4f1cdadbbb5c9 | Converts a string into an MD5 hash value. |
URL decode | {{ "'Hello%21'+from+Ortto" | url_decode }} | Hello!' from Ortto | Decodes URL-encoded strings. |
URL encode | {{ "lauren@email.com" | url_encode }} | lauren%40email.com | Encodes unsafe URL characters |