如何在smarty中显示有限的字符?

时间:2010-12-18 09:08:48

标签: smarty

我收到smarty中的段落内容。在显示时我只需要显示25个字符,如何限制smarty中的字符。

<p>{$myresult}</p>

现在我只是在展示。如何从聪明的内容中只显示25个字符

2 个答案:

答案 0 :(得分:11)

聪明地使用Truncate ......

<强> CODES

{$articleTitle}
{$articleTitle|truncate}
{$articleTitle|truncate:30}
{$articleTitle|truncate:30:""}
{$articleTitle|truncate:30:"---"}
{$articleTitle|truncate:30:"":true}
{$articleTitle|truncate:30:"...":true}
{$articleTitle|truncate:30:'..':true: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 after
Two Sisters Reunite after---
Two Sisters Reunite after Eigh
Two Sisters Reunite after E...
Two Sisters Re..ckout Counter.

答案 1 :(得分:0)

如果安装了子串过滤器(我认为它已安装默认值):

{$myresult|substring:1:25}

如果没有,请查看此网站:

http://smarty.incutio.com/?page=substring