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:

Mary had ...

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:

Mary had a 

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:

Mary ha...

FAQ

  1. 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

  • truncatewords_old
Document generated by Confluence on Feb 12, 2013 09:09