smarty 自定义函数
2015-10-09 14:44
363 查看
<?php
//创建smarty对象
require_once("./libs/Smarty.class.php");
$smarty = new Smarty();
//自定义一个函数
//说明:(1)、$arr为一个数组;(2)、tpl调用形式{test times="4" size="5" con="hello,world" color="red"}
function test($arr){
$str = "";
for($i=0;$i<$arr['times'];$i++){
$str .= "<font size='".$arr['size']."' color='".$arr['color']."'>".$arr['con']."</font>";
}
return $str;
}
//注册函数 registerPlugin
$smarty->registerPlugin("function","test","test");//第二个参数是模板文件调用的函数名称,可变;第三个参数是上面自定义的函数名称;相应于一个对应关系
$smarty->display("temp.tpl");
?>
//创建smarty对象
require_once("./libs/Smarty.class.php");
$smarty = new Smarty();
//自定义一个函数
//说明:(1)、$arr为一个数组;(2)、tpl调用形式{test times="4" size="5" con="hello,world" color="red"}
function test($arr){
$str = "";
for($i=0;$i<$arr['times'];$i++){
$str .= "<font size='".$arr['size']."' color='".$arr['color']."'>".$arr['con']."</font>";
}
return $str;
}
//注册函数 registerPlugin
$smarty->registerPlugin("function","test","test");//第二个参数是模板文件调用的函数名称,可变;第三个参数是上面自定义的函数名称;相应于一个对应关系
$smarty->display("temp.tpl");
?>
相关文章推荐
- 更新Cocos2D支持Xcode 7
- 如何查看真机的沙盒(图文教程)
- 更新Cocos2D支持Xcode 7
- 更新Cocos2D支持Xcode 7
- MATLAB中如何输出漂亮的公式
- JQuery EasyUI DataGrid 纵向(转置)表格插件 TransposedView
- NGINX开篇
- General Problem Solving Techniques [Intermediate-1]~D - Fabled Rooks
- oracle 第02章 基本操作
- quick-cocos2d-x数据存储 UserDefault GameState io
- 系统设计之BS与CS结构分析
- PHP+table生成柱状图
- 欢迎使用CSDN-markdown编辑器
- 一个最符合中国国情的工作流设计参考(包括PHP实现)
- 自定义字节流缓冲区,演示缓冲区的工作原理
- OBS (open boardcast server)结构分析
- Redis初级介绍
- Loadrunner:安装LR11时提示缺少vc2005_sp1_with_atl_fix_redist
- NGINX(七)分段下载
- linux 输入子系统(2) platform device