smarty自定义函数

assign 用于在模板被执行时为模板变量赋值.

例如:

{assign var="name" value="Bob"}


counter 用于输出一个记数过程. counter 保存了每次记数时的当前记数值. 用户可以通过调节 interval 和 direction 调节该值. 也可以决定是否输出该值. 如果需要同时运行多个计数器,必须为它们指定不同的名称. 如果没有指定名称,模板引擎使用 "default" 作为缺省值.

例如:

{counter start=0 skip=2 print=false}{counter}<br>{counter}<br>{counter}<br>{counter}<br>


Cycle 用于轮转使用一组值. 该特性使得在表格中交替输出颜色或轮转使用数组中的值变得很容易.

例如:

{section name=rows loop=$data}<tr bgcolor="{cycle values="#eeeeee,#d0d0d0"}"> <td>{$data[rows]}</td></tr>{/section}


eval 按处理模板的方式计算取得变量的值. 该特性可用于在配置文件中的标签/变量中嵌入其它模板标签/变量.

例如:

setup.conf----------emphstart = <b>emphend = </b>title = Welcome to {$company}'s home page!ErrorCity = You must supply a {#emphstart#}city{#emphend#}.ErrorState = You must supply a {#emphstart#}state{#emphend#}.index.tpl---------{config_load file="setup.conf"}{eval var=$foo}{eval var=#title#}{eval var=#ErrorCity#}{eval var=#ErrorState# assign="state_error"}{$state_error}

自定义函数 html_checkboxes 根据给定的数据创建复选按钮组. 该函数可以指定哪些元素被选定. 要么必须指定 values 和 ouput 属性,要么指定 options 替代. 所有的输出与 XHTML 兼容


例如:

index.php

require('Smarty.class.php');$smarty = new Smarty;$smarty->assign('cust_ids', array(1000,1001,1002,1003));$smarty->assign('cust_names', array('Joe Schmoe','Jack Smith','Jane Johnson','Charlie Brown'));$smarty->assign('customer_id', 1001);$smarty->display('index.tpl')


index.tpl:{html_checkboxes values=$cust_ids checked=$customer_id output=$cust_names separator="<br />"}

textformat 用于格式化文本. 该函数主要清理空格和特殊字符,对段落按单词边界换行和行缩进等段落格式化处理.


例如:

{textformat wrap=40}This is foo.This is foo.This is foo.This is foo.This is foo.This is foo.This is bar.bar foo bar foo foo.bar foo bar foo foo.bar foo bar foo foo.bar foo bar foo foo.bar foo bar foo foo.bar foo bar foo foo.bar foo bar foo foo.{/textformat}

mailto 自动生成电子邮件链接,并根据选项决定是否对地址信息编码. 电子邮件地址编码使得网络嗅探程序难以收集到电子邮件地址信息.




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值