本文簡單講述了Smarty的模板變量輸出方法。分享給大家供大家參考,具體如下:
config.inc.php配置文件如下:
include_once('smarty/Smarty.class.php');$smarty=new Smarty();$smarty->config_dir="smarty/Config_File.class.php";$smarty->caching=false; //是否開啟緩存$smarty->template_dir="./templates"; //模板目錄$smarty->compile_dir="./templates_c"; //編譯目錄$smarty->cache_dir="./smarty_cache"; //緩存目錄$smarty->left_delimiter="<{";$smarty->right_delimiter="}>";
index.php文件如下:
include('./config.inc.php');$title="php測試標題";$content="smarty練習!";$newstext[]=array("name"=>"php程序測試","date"=>"2015-08-01");$newstext[]=array("name"=>"php視頻教程","date"=>"2015-08-02");$newstext[]=array("name"=>"smarty學習","date"=>"2015-08-03");$row=array("標題","姓名","年齡");$smarty->assign("title",$title);$smarty->assign("row",$row);//一個數組傳遞多個值$smarty->assign("shownewstext",$newstext);//二維數組傳遞多個值$smarty->assign("content",$content);$smarty->display('index.htm');
運行結果如下:
測試數組:標題 | 姓名 | 年齡 --------------------------------------------------------------------------------測試內容為:smarty練習! 循環新聞內容為:php程序測試 - 2015-08-01php視頻教程 - 2015-08-02smarty學習 - 2015-08-03
希望本文所述對大家基于Smarty模板的php程序設計有一定幫助作用。
新聞熱點
疑難解答
圖片精選