Truncate in Smarty
This truncates a variable to a character length, default is 80. As an optional second parameter, we can specify a string of text to display at the end if the variable was truncated. The characters in the string are included with the original truncation length. By default, truncate will attempt to cut off at a word boundary. If we want to cut off at the exact character length, pass the optional third parameter of true.
Example
<?php
$smarty->assign(’input’, ‘This is test string which use truncate.’);
?>
In template we can have like,
{$input}
{$input|truncate}
{$input|truncate:30:”—”}
{$input|truncate:30:”…”:true}
The output will be as follows:
This is test string which use truncate.
This is test string which use truncate.
This is test—
This is test st…
