smarty模板引擎总结七系统插件
smarty插件
1. smarty系统的插件
2. 自定义插件
smarty的系统的标签 系统的插件 函数插件
插件目录 /smarty/plugins/
插件: 就是smarty中能够完成一定功能的函数
系统插件:
单选框
{html_radios name="" output="" values="" checked="" separator=""}
html_radios: 标签名
name: 单选按钮组的名字
output:显示的数据组成的一维索引数组
values: 每个单选按钮value值组成的一维的索引数组
checked: 被默认选中按钮的value值,只能有一个
separator:按钮组的样式
{html_radios name="" options="" checked="" separator=""}
options: values作为数组的key 显示的数据作为values的一维的关联数组
复选框
{html_checkboxes name="" output="" values="" checked="" separator=""}
html_checkboxes: 标签名
name:单选按钮的名字
output:显示的数据内容组成的一维索引数组
values: 每个单选按钮value值组成的一维的索引数组
separator:按钮组的样式
checked:可以是单个数值也可以是被选中的按钮value组成的一维索引数组
{html_checkboxes name="" options="' checked="" separator=""}
options: values 做key output 做value 的一维关联数组
下拉列表框
<select name="">
<option value="">显示的内容</option>
</select>
{html_options name="" output="" values="" selected=""}
时间插件
{html_select_time} H:i:s
日期插件
{html_select_date start_year="" end_year=""}
start_year:起始的年份
end_year:终止的年份
month_format="%m"
display_months=false
display_days=false
在/smarty目录下建立一个plugins.php,在/template/建立一个plugins.html
plugins.php
<?phprequire("./Smarty.inc.php");//引入smarty的初始化文件$sex="女,男";//真是开发的时候数据是这样写入数据库$sex=explode(",",$sex);//用逗号分割成一个数组$smarty->assign("sex",$sex);$hobby="篮球,足球,台球";$hobby=explode(",",$hobby);$smarty->assign("hobby",$hobby);$arr=array("篮球","足球","台球");$selected=array("篮球","足球");//这里是上面数组里的值不是key$smarty->assign("selected",$selected);$smarty->assign("arr",$arr);$area['addr']=array("江苏","河南","上海","浙江","北京");$area['id']=array(110,120,130,140,150);$smarty->assign($area);$lasttime=time();$smarty->assign("lasttime",$lasttime);$smarty->display("plugins.html");?>
plugins.html
<!DOCTYPEhtml><html><head><title></title><metacharset="utf-8"></head><body><h4>单选框</h4>{html_radiosname="sex"options=$sexchecked="0"separator=""}<hr/><h4>单选框</h4>{html_radiosname="sex"options=$sexchecked="0"separator="<br/>"}<hr/><h4>复选框</h4>{html_checkboxesname="hobby"output=$hobbyvalues=$hobbychecked=""separator=""}<hr/><h4>已勾选复选框</h4>{html_checkboxesname="hobby"output=$arrvalues=$arrchecked=$selectedseparator=""}<hr/><h4>下拉框</h4>{html_optionsname="address"output=$addrvalues=$idselected=""}<hr/><h4>时间</h4>{$lasttime|date_format:date("Y-m-dH:i:s")}</body></html>
页面效果
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。