Smarty中注释和截断的功能详解

编写代码时不可避免地要使用注释,大多数时候这些HTML的注释函数,都不会显示给浏览器,下面爱站技术频道小编将为大家介绍Smarty中注释和截断的功能详解,非常实用,希望能帮到大家。

注释

复制代码 代码如下:

{* 这是一个单行Smarty注释 来自于jb51.net,网页源代码里看不见*}

 

{* 这是一个多行
   Smarty注释
   并不发送到浏览器
*}

 

模板注释由星号包围,继而由分隔符包围,型如:{* 这是一个注释 *}。Smarty注释不会在最终模板的输出中显示,这点和不同。前者对于在模板中插入内部注释有用,因为没有人能看到。;-)

http://www.itlearner.com/code/smarty_cn/language.basic.syntax.html

截断truncate

复制代码 代码如下:

$smarty->assign(‘hxtitle’, ‘Two Sisters Reunite after Eighteen Years at Checkout Counter.’);

 

模板为:

复制代码 代码如下:

{$hxtitle}

{$hxtitle|truncate}

{$hxtitle|truncate:30}

{$hxtitle|truncate:30:””}

{$hxtitle|truncate:30:”—“}

{$hxtitle|truncate:30:””:true}

{$hxtitle|truncate:30:”…”:true}

{$hxtitle|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.

上面就是爱站技术频道小编介绍的Smarty中注释和截断的功能详解,这里还有更多的编程技巧,感谢大家的一路的支持。