您好,欢迎访问一九零五行业门户网

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

smarty是一个使用php写出来的模板引擎。它分离了逻辑代码和外在的内容,提供了一种易于管理和使用的方法。这篇文章主要介绍了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.');
模板为:
复制代码 代码如下:
{$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.
可以不用在php里截取了:http://www.itlearner.com/code/smarty_cn/language.modifier.truncate.html
相关推荐:
smarty如何嵌套循环
smarty模板如何使用变量调节器
smarty如何生成简单的表单元素
以上就是smarty中的注释和截断功能详解的详细内容。
其它类似信息

推荐信息