truncatewords Filter

Cuts a string down to a given number of words.

Parameters

Parameter Required Description
length Yes string Number of words to limit string to.
append No string String to append to the end of the truncated string. This defaults to a 3-character ellipsis (...).

Category

String Filters

Description

The truncatewords filter cuts a string off at a given word count. A second parameter indicates a string to append to the end of the chopped string.

      {{ "Long, long, long, long sentence." | truncate: 4 }}
      {{ "Long, long, long, long sentence." | truncate: 4, '.' }}
      

Output

      Long, long, long, long...
      Long, long, long, long.