The truncate modifier truncates a string at the given point. You can specify after how many characters you will truncate it. This modifier is extremely helpful for article management websites where only truncated excerpts of articles are needed to be shown in the front page. This modifier takes three optional parameters. The first parameter is the number of characters after which the truncation occurs. The second parameter is what will replace the truncated part of the string; by default it is an ellipsis. The third parameter indicates whether the truncate modifier should truncate in the middle of a word of not. If you set the third parameter as false, then it will not truncate in the middle of a word but at the start of it.
truncate.tpl
truncate.php
Output
This is some lo... This is some...
truncate.tpl
{$sometext|truncate:18:"...":true}<br />
{$sometext|truncate:18:"...":false}
{$sometext|truncate:18:"...":false}
<?
include("libs/smarty.class.php");
$smarty = new smarty();
$smarty->assign("sometext", "This is some long text to truncate");
$smarty->display("truncate.tpl");
?>
include("libs/smarty.class.php");
$smarty = new smarty();
$smarty->assign("sometext", "This is some long text to truncate");
$smarty->display("truncate.tpl");
?>
This is some lo... This is some...