An introduction to the use of smarty as a truncated string function

  • 2020-06-15 07:56:28
  • OfStack

smarty truncate intercepts the string
Truncates a character of some length from the beginning of a string. The default length is 80
Specifies the second parameter as the length of the truncated string
By default, smarty intercepts to the end of a word,
If you want to be precise about how many characters to intercept you can use the third argument and set it to "true"
Specific usage is as follows:

//index.php $smarty = new Smarty; 
$smarty->assign('articleTitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.'); 
$smarty->display('index.tpl'); 
//index.tpl 
{$articleTitle} 
{$articleTitle|truncate} 
{$articleTitle|truncate:30} 
{$articleTitle|truncate:30:""} 
{$articleTitle|truncate:30:"---"} 
{$articleTitle|truncate:30:"":true}
{$articleTitle|truncate:30:"...":true}

Output results:
Two Sisters Reunite after Eighteen Years at Checkout Counter.
Two Sisters Reunite after Eighteen Years at Checkout Counter.
Two Sisters Reunite after...
Two Sisters Reunite after
Two Sisters Reunite after -
Two Sisters Reunite after Eigh
Two Sisters Reunite after E...

Related articles: