truncate - Liquid Filter Reference
On this page
Description
Shortens a string down to the number of characters passed as an argument. If the specified number of characters is less than the length of the string, an ellipsis (…) is appended to the string and is included in the character count.
| Property | Value |
|---|---|
| Return Type | string |
| Category | text |
Examples
liquid
{{ "Mary had a little lamb." | truncate: 15 }}
Output: Mary had a l...
truncate takes an optional second argument that specifies the sequence of characters to be appended to the truncated string. By default this is an ellipsis (…), but you can specify a different sequence
liquid
{{ "Mary had a little lamb." | truncate: 15, "--" }}
Output: Mary had a li--
You can avoid showing trailing characters by passing a blank string as the second argument
liquid
{{ "Mary had a little lamb." | truncate: 15, "" }}
Output: Mary had a litt