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
<?php require("./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
<!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8"> </head> <body> <h4>單選框</h4> {html_radios name="sex" options=$sex checked="0" separator=""} <hr/> <h4>單選框</h4> {html_radios name="sex" options=$sex checked="0" separator="<br/>"} <hr/> <h4>復選框</h4> {html_checkboxes name="hobby" output=$hobby values=$hobby checked="" separator="" } <hr/> <h4>已勾選復選框</h4> {html_checkboxes name="hobby" output=$arr values=$arr checked=$selected separator="" } <hr/> <h4>下拉框</h4> {html_options name="address" output=$addr values=$id selected=""} <hr/> <h4>時間</h4> {$lasttime|date_format:date("Y-m-d H:i:s")} </body> </html>
頁面效果
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。