class Truncate extends Twig_Extension

A Tiwg extension that truncates text while preservice HTML tags.

Based on http://alanwhipple.com/2011/05/25/php-truncate-string-preserving-html-tags-words/

Methods

getFilters()

No description

getName()

No description

string
truncate(string $text, integer $length = 100, string $ending = '...', boolean $exact = false, boolean $considerHtml = true)

Truncates a string up to a number of characters while preserving whole words and HTML tags

Details

at line 14
getFilters()

at line 27
getName()

at line 43
string truncate(string $text, integer $length = 100, string $ending = '...', boolean $exact = false, boolean $considerHtml = true)

Truncates a string up to a number of characters while preserving whole words and HTML tags

Parameters

string $text String to truncate.
integer $length Length of returned string, including ellipsis.
string $ending Ending to be appended to the trimmed string.
boolean $exact If false, $text will not be cut mid-word
boolean $considerHtml If true, HTML tags would be handled correctly

Return Value

string Truncated string.