Use the truncate Liquid filter when a merge field or export may return more characters than you want to display. The filter shortens the value to a specified character count and can optionally append an ending string.
⭐ Get Inspired
This article was adapted from a post by Technolutions staff in the Slate Community Forums' Get Inspired space. Have a great idea for a Get Inspired post? Let us know!
Shorten a value with the default ellipsis
Add | truncate: followed by the maximum number of characters.
{{ academic_major | truncate: 8 }}If academic_major returns journalism, this outputs:
journ...The ellipsis is included in the character count. In this example, the output contains five characters from the original value plus the three-character ellipsis.
Shorten a value without an ellipsis
Add a blank string as the second argument when you want the output to stop at the character limit without adding an ellipsis.
{{ academic_major | truncate: 8, "" }}If academic_major returns journalism, this outputs:
journaliUse a custom ending
Add a custom string as the second argument when the shortened value should end with custom text.
{{ academic_major | truncate: 21, ", and so on" }}If academic_major returns social anthropology, this outputs:
social ant, and so on📝 Note
The custom ending counts toward the total character limit. If the custom ending is longer than the limit, increase the limit or use a shorter ending.
Where to use truncate
The truncate filter is useful in places where Liquid markup can render dynamic values, including mailings, portals, and other content that supports Liquid markup. If you need to shorten values directly in a query result, consider using a query formula instead.