Truncating text and specifying the amount of characters

Permalink
Hi There,

I need to truncate some a collection title to ensure it fits into a slider properly.

I'm loading the text helper at the top of the template like this:
$textHelper = Loader::helper("text");


Then displaying the title in the markup further down like this:
<p><?php  echo $textHelper->shorten($cobj->getCollectionName(),$controller->truncateChars); ?></p>


How do I limit the text to a specific character amount - after searching I found this so tried added at the top and where the markup is rendered but I obviously added to the wrong place.
$truncateChars = 120;


Any help would be much appreciated.

Cheers

Ben

 
jordanlev replied on at Permalink Best Answer Reply
jordanlev
Is this in the page list block or something else? If it's the page list block you can just set the character truncation when you edit the block (it's something like "truncate excerpts after this number of characters").

If this isn't the page list block then replace the "$controller->truncateChars" bit with just the number you want, so that line would look like this:
<p><?php  echo $textHelper->shorten($cobj->getCollectionName(), 120); ?></p>