This page last changed on Aug 15, 2012 by yuriy.kalynovskiy@involver.com.
Overview
This filter truncates a string if it's larger than a specified number of words.
Attributes
type |
required |
description |
integer |
true |
The maximum number of words in the resulting string. |
Examples
Shorten a string to 4 words
If you wanted to take the string "Mary had a little lamb." and truncate it to 4 words, you'd use:
{{ "Mary had a little lamb." | truncatewords: 4 }}
The above code results in the following string:
Shorten the same string to 3 words
If you wanted to take the string "Mary had a little lamb." and truncate it to 3 words instead of 4, you'd use:
{{ "Mary had a little lamb." | truncatewords: 3 }}
The above code results in the following string:
FAQ
- Can I make sure that I don't get a string longer than n characters?
No, if you need to truncate to a certain number of characters, you can use the truncate filter instead (see below).
Related Topics
|