silverstripe/silverstripe-framework — pull request #3566 by antons- (2014-10-17 02:56:07+00:00)
Title: API Text - Limit characters to closest word

This new function builds on top of the functionality in Text->LimitCharacters(), but it truncates the value to the closest complete word.

There are several advantages to this over Text->LimitCharacters eg. the ellipsis (...) is always added after a complete word as sometimes in Text->LimitCharacters it can add the ellipsis in the middle of a word, or worse, at the end of a space or other punctuation. This function also trims any whitespace/punctuation on the end before adding the ellipsis.

It gives more control especially when using a tile frontend like Isotope, where the tile height is fixed and cannot adjust to the content length.

The limitation of the function is that it strips all HTML tags out of the value, but then its only intended for showing a small snippet of the text in a restrictive layout.