smarty:
1、 自定义函数(自定义标签)
1) php文件function定义函数
注册步骤(register_funcion()、register_block())
Tpl文件类似于html标签
<{title num=”10”}>
成对出现—块
<{title}>……<{/title}>
2)当做插件
./plugins.
*.function.*.php
Function smarty_function.
*.block.*.php
Function smarty_block.
扩展smarty标签功能模块,自己进行编辑
2、 内建函数(类似自定义函数)
不能进行
Include:包含子模板
Include(“head.tpl”);
Config_load
Capture:<{capure}>……</capture>成批量的重复使用
使用smarty的保留变量去调用
$smarty.capture.
If..elseif..else /if: elseif 中间不要出现空格
条件表达式不能加()
==><
Eq gt lt ge le(大于等于)
Foreach—foreach 关联数组 索引数组
From=”要循环的数组名”name=””
变量:$smarty.foreach.name1.first last total etc.
Section—for 索引数组
$data[]=$row
给本次循环指定一个名称
Name=”out”
$data[out].ip
….
缓存
Cache:提高效率
*.php *.tpl
Smarty-- 合并后编译(php与html混合)
Templates_c
*.php
优点:省略了重新合并、编译的时间
连接数据库不能省略
增加缓存:./cache/*.html
减少了访问数据库的次数
Display(””,”任意名称”)
生成静态几个方法
$_GET[“”]
$_SERVER[“REQUST_URI”]
局部缓存
实时性要求比较高
例如:登陆用户名称
欢迎Amdin登陆到****
例如:时间日期
解决步骤:自定义函数(自定义插件)
1)指定该函数名称nocache(不缓存)
<{}>admin<{/}>
2) 新建文件./plugins/b
3) lockfunction
…
Tpl->assign(“date,date(“H:i:s”)”);
…
*.tpl
<{nocache}><{$date}><{/nocache}>
所有插件默认都是被缓存的
Smarty.
$this->is_cached()
修改成不被缓存???
第三种:smarty内建函数insert
*.php
Function fun1($args,$content){return $content;}
*.tpl
<{insert name=”fun1”}>