This page last changed on Jan 20, 2011 by justin.johnson@involver.com.
Overview
This filter truncates a string if it's larger than a specified number of characters.
Attributes
type |
required |
description |
integer |
true |
The maximum number of characters in the resulting string. |
string |
false |
The characters to be used in place of '...' when truncating |
Examples
Shorten a string to 12 characters
If you wanted to take the string "Mary had a little lamb." and truncate it to 12 characters, you'd use:
{{ "Mary had a little lamb." | truncate: 12 }}
The above code results in the following string:
Shorten a string to 12 characters
If you wanted to take the string "Mary had a little lamb." and truncate it to 12 characters without the '...', you'd use:
{{ "Mary had a little lamb." | truncate: 12, ' ' }}
The above code results in the following string:
Shorten the same string to 10 characters
If you wanted to take the string "Mary had a little lamb." and truncate it to 10 instead of 12 characters, you'd use:
{{ "Mary had a little lamb." | truncate: 10 }}
The above code results in the following string:
FAQ
- Can I make sure that I truncate on a word boundary?
No, if you need to truncate to a certain number of words, you can use the truncatewords filter instead (see below).
Related Topics
|