truncate
截取

Parameter PositionTypeRequiredDefaultDescription
1integerNo80 This determines how many characters to truncate to.
指定截取多少字符
2stringNo... This is the text to append if truncation occurs.
截取后加在截取词后的字符串
3booleanNofalse This determines whether or not to truncate at a word boundary (false), or at the exact character (true).
检查是否截取到词的边界

This truncates a variable to a character length, default is 80.
As an optional second parameter, you 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 you want to cut off at the exact character length, pass the optional third parameter of true.

截取字符串开始的一段.默认是80个.
你可以指定第二个参数作为在截取的那段字符串后加上什么字符.
默认情况下,smarty会截取到一个词的末尾,
如果你想要精确的截取多少个字符,把第三个参数改为"true"

Example 5-21. truncate
例5-21.截取

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:



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...