Skip to content
Log in

truncatewords - Liquid Filter Reference

On this page

Description

Shortens a string down to the number of words passed as an argument. If the specified number of words is less than the number of words in the string, an ellipsis (…) is appended to the string.

Property Value
Return Type string
Category text

Examples

liquid {{ "Mary had a little lamb." | truncatewords: 3 }}

Output: Mary had a...

truncatewords 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." | truncatewords: 3, "--" }}

Output: Mary had a--

You can avoid showing trailing characters by passing a blank string as the second argument

liquid {{ "Mary had a little lamb." | truncatewords: 3, "" }}

Output: Mary had a

Was this article helpful?

Was this article helpful?