System:Template:truncateText

From Aspen Documentation

Used for truncating long text at word X, and adding an ellipse and a link to "read more".

Since 1.0

Contents

Arguments

string truncateText (string $phrase, [integer $blurb_word_length = 40], [string $more_link = false])

phrase
The text that needs to be truncated.
blurb_word_length
The number of words to truncate after. The default is 40.
more_link
An html anchor to a place where the user can continue reading.

Returns

Returns a string.

Notes

  • The read more link does not auto-generate using the template url functions. Currently, you must provide the html anchor entirely.

Examples

$phrase = 'Lorem Ipsum is simply dummy text of the printing and typesetting 
industry. Lorem Ipsum has been the industrys standard dummy text ever since the
1500s, when an unknown printer took a galley of type and scrambled it to make
a type specimen book. It has survived not only five centuries, but also the
leap into electronic typesetting, remaining essentially unchanged.';
print $this->truncateText($phrase);

The result is the same block of text truncated after the fortieth word:

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a…