left_delimiter="{"; #左修饰符
$smarty->right_delimiter="}"; #右修饰符
$tpl=$smarty->template_dir ="./template"; #模板文件
$smarty->cache_dir ="./cache"; #缓存文件
$smarty->compile_dir ="./template_c"; #编译文件
$smarty->caching = true; #开启缓存
$smarty->cache_lifetime = 100; #生命周期
#smarty 数组遍历
$test = array(
array(
"title"=>"中文",
"author"=>"周",
"content"=>"你好 smarty"
),
array(
"title"=>"english",
"author"=>"zeopean",
"content"=>"hello Samrty"
)
);
#定义元素
$smarty->assign("test",$test);
#smarty 类与对象的使用
class Obj{
function func($param){
return $param[0].'====='.$param[1];
}
}
#实例化对象
$obj = new Obj();
$smarty->assign('obj',$obj);
#Smarty 函数
function test($param){
$p1= $param['p1'];
$p2= $param['p2'];
return $p1.'======='.$p2;
}
#注册函数
$smarty->registerPlugin('function','test1','test');
#输出
$smarty->display("index.tpl");
?>
index.tpl 模板文件
foreach 测试
{foreach $test as $test1} #使用as 关键字,在3的版本是支持的
{$test1.title}
{$test1.author}
{$test1.content}
{/foreach} #foreach 结束[object Object]{foreach item=test1 from=$test} #别名 item 和 from 的使用
{$test1.title}
{$test1.author}
{$test1.content}
{/foreach} #foreach 结束[object Object] include 文件 引入
#在include文件中定义一个{$title}变量
{include file='include.tpl' title='test include!'}[object Object] section 循环
{section name=test1 loop=$test}
{$test[test1].title}
{$test[test1].author}
{$test[test1].content}
{/section}[object Object] class && obj 的使用
{$obj->func(array('1','11'))}[object Object] function 函数的使用
{test1 p1='zeopean' p2='周'}
smarty 中一些方法的使用
精选 转载上一篇:smarty 中一些方法的使用
下一篇:smarty 中一些方法的使用
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Java中一些常用的方法
Java中的一些方法
Java 程序运行 文件读写 赋值 文件路径 -
04 kafka 中一些常用的配置的使用
呵呵 也是最近有一些 搭建 kafka 的环境的需求然后 从新看了一下 一部分的配置情况, 这里 大致理一下 一些我这里比较关心的配置。
kafka java config apache sed