escape [编码]
参数位置 参数类型 必需 可用参数 默认 描述
1 string No html,url,quotes html 使用何种编码格式
描述
用于html转码,url转码,在没有转码的变量上转换单引号,十六进制转码,十六进制美化转码。默认是html转码。
实例
{$articleTitle}
{$articleTitle|escape}
{$articleTitle|escape:"html"} {* escapes& " ' <> *}
{$articleTitle|escape:"url"}
{$articleTitle|escape:"quotes"}
nl2br [换行符替换成
]
描述
所有的换行符将被替换成
.功能同PHP中的nl2br()函数一样.
例子
{$articleTitle|nl2br}
输出
Sun or rain expected<br />today, dark tonight
default [默认值]
参数位置 参数类型 必需 默认 描述
1 string No empty 这是变量为空的时候的默认输出。
描述
为空变量设置一个默认值。
当变量为空或者未分配的时候,将由给定的默认值替代输出。
例子
{$articleTitle|default:"no title"}
{$myTitle|default:"no title"}
输出
Dealers Will Hear Car Talk at Noon.
no title
truncate [截取]
参数位置 参数类型 必需 默认 描述
1 integer No 80 截取字符的数量。
1 string No …… 截取后追加在截取词后面的字符串。
1 boolean No false 是截取到词的边界(假)还是精确到字符(真)。
描述
从字符串开始处截取某长度的字符.默认是80个.
你也可以指定第二个参数作为追加在截取字符串后面的文本字串.该追加字串被计算在截取长度中。
默认情况下,smarty会截取到一个词的末尾。
如果你想要精确的截取多少个字符,把第三个参数改为”true”
例子
{$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 after
Two Sisters Reunite after---
Two Sisters Reunite after Eigh
Two Sisters Reunite after E...
strip_tags [去除html标签]
描述
去除<和>标签,包括在<和>之间的任何内容.
例子
{$articleTitle}
{$articleTitle|strip_tags}
输出:
Blind Woman Gets <font face="helvetica">New Kidney</font> from Dad she Hasn't
Seen in <b>years</b>.
Blind Woman Gets New Kidney from Dad she Hasn't Seen in years.
原文链接
http://www.uedsc.com/ecshop-variable-control-label.html