Is there a function to limit the number of words to display?
Yes! With truncate
Intercepts a length of characters from the beginning of a string. The default is 80.
You can also specify the second argument as the text string appended to the Intercept string. The append string is computed in the intercept length.
By default, Smarty is truncated to the end of a word.
If you want to accurately intercept the number of characters, change the third parameter to "true"
CODE:
index.php:
$smarty =new Smarty;
$smarty->assign (' ArticleTitle ', ' both sisters reunite after eighteen years at Checkoutcounter. ');
$smarty->display (' Index.tpl ');
Www.2cto.com
INDEX.TPL:
{$articleTitle}
{$articleTitle |truncate}
{$articleTitle |truncate:30}
{$articleTitle |truncate:30: ""}
{$articleTitle |truncate:30: "---"}
{$articleTitle |truncate:30: "": true}
{$articleTitle |truncate:30: "...": true}
OUTPUT:
Sisters reunite after eighteen years at Checkout Counter.
Sisters reunite after eighteen years at Checkout Counter.
Sisters reunite after ...
Sisters reunite after
Sisters reunite after---
Sisters reunite after Eigh
Sisters reunite after E ...
http://www.bkjia.com/PHPjc/478558.html www.bkjia.com true http://www.bkjia.com/PHPjc/478558.html techarticle are there any features that limit the number of words to display? Use truncate to intercept a certain length of character from the beginning of a string. The default is 80. You can also specify a second parameter as the append in the Intercept string ...