smarty模板中truncate的使用

来源:互联网 发布:验证json格式 编辑:程序博客网 时间:2024/05/20 00:38

smarty模板中truncate的使用

truncate:截取
1.从字符串开始处截取某长度的字符,默认是80个,你也可以指定第二个参数作为追加在截取字符串后面的文本字串.该追加字串被计算在截取长度中。默认情况下,smarty会截取到一个词的末尾。如果你想要精确的截取多少个字符,把第三个参数改为”true”;
2.例:截取

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}

输出结果:

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 afterTwo Sisters Reunite after---Two Sisters Reunite after EighTwo Sisters Reunite after E...
0 0