truncatewords
Truncates a string down to a given number of words.
If the specified number of words is less than the number of words in the string, then an ellipsis (...) is appended to
the truncated string.
HTML tags are treated as words, so you should strip any HTML from truncated content. If you don't strip HTML, then closing HTML tags can be removed, which can result in unexpected behavior.
HTML tags are treated as words, so you should strip any HTML from truncated content. If you don't strip HTML, then closing HTML tags can be removed, which can result in unexpected behavior.
Caution: HTML tags are treated as words, so you should strip any HTML from truncated content. If you don't strip HTML, then closing HTML tags can be removed, which can result in unexpected behavior.
Code
{{ article.content | strip_html | truncatewords: 15 }}Data
{
"article": {
"content": "<p>We've all had this problem before: we peek into the potions vault to determine which potions we are running low on, and the invisibility potion bottle looks completely empty.</p>\n<p>...</p>\n<p> </p>"
}
}Output
Output
We've all had this problem before: we peek into the potions vault to determine which...Specify a custom ellipsis
You can provide a second parameter to specify a custom ellipsis. If you don't want an ellipsis, then you can supply an empty string.
Code
{{ article.content | strip_html | truncatewords: 15, '--' }}
{{ article.content | strip_html | truncatewords: 15, '' }}Data
{
"article": {
"content": "<p>We've all had this problem before: we peek into the potions vault to determine which potions we are running low on, and the invisibility potion bottle looks completely empty.</p>\n<p>...</p>\n<p> </p>"
}
}Output
Output
We've all had this problem before: we peek into the potions vault to determine which--
We've all had this problem before: we peek into the potions vault to determine which