truncate_words
Truncates a sentence to a given number of words.
Specification
{{ text | truncate_words: number_of_words=30, end_string='…' }}
Parameter | Description | Example Values |
---|---|---|
text (required) | The given text. | “this is my title” |
end_string | The number of words to truncate the sentence to. | 30 |
number_of_words | Specifies what to add to the end of the sentence to indicate that it was truncated. | ‘…’ |
Examples
{{ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vel placerat libero.' | truncate_words: 10 }}
This will output “Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vel… “
{{ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vel placerat libero.' | truncate_words: 10, ' (text truncated)' }}
This will output “Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vel (text truncated)”