Smarty是一个使用PHP写出来的模板引擎。它分离了逻辑代码和外在!本文来源gaodai#ma#com搞*!代#%^码网5
搞gaodaima代码
的内容,提供了一种易于管理和使用的方法。这篇文章主要介绍了Smarty中的注释和截断功能介绍,这两个功能都是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.');<br />
模板为:
{$hxtitle}<br />{$hxtitle|truncate}<br />{$hxtitle|truncate:30}<br />{$hxtitle|truncate:30:""}<br />{$hxtitle|truncate:30:"---"}<br />{$hxtitle|truncate:30:"":true}<br />{$hxtitle|truncate:30:"...":true}<br />{$hxtitle|truncate:30:'..':true:true}
输出为:
Two Sisters Reunite after Eighteen Years at Checkout Counter.<br />Two Sisters Reunite after Eighteen Years at Checkout Counter.<br />Two Sisters Reunite after...<br />Two Sisters Reunite after<br />Two Sisters Reunite after---<br />Two Sisters Reunite after Eigh<br />Two Sisters Reunite after E...<br />Two Sisters Re..ckout Counter.
可以不用在PHP里截取了:http://www.itlearner.com/code/smarty_cn/language.modifier.truncate.html
相关推荐:
smarty如何嵌套循环
Smarty模板如何使用变量调节器
Smarty如何生成简单的表单元素
以上就是Smarty中的注释和截断功能详解的详细内容,更多请关注搞代码gaodaima其它相关文章!