smarty簡單模板變量輸出方法 原創(chuàng)
原創(chuàng) 更新時間:2016年07月09日 23:43:06 原創(chuàng) 投稿:shichen2014
這篇文章主要介紹了smarty簡單模板變量輸出方法,涉及Smarty模板中數(shù)組的定義、使用及assign方法進行變量替換的相關(guān)技巧,需要的朋友可以參考下
本文簡單講述了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);//一個數(shù)組傳遞多個值 $smarty->assign("shownewstext",$newstext);//二維數(shù)組傳遞多個值 $smarty->assign("content",$content); $smarty->display('index.htm');
運行結(jié)果如下:
測試數(shù)組:標題 | 姓名 | 年齡 -------------------------------------------------------------------------------- 測試內(nèi)容為:smarty練習! 循環(huán)新聞內(nèi)容為: php程序測試 - 2015-08-01 php視頻教程 - 2015-08-02 smarty學習 - 2015-08-03
希望本文所述對大家基于Smarty模板的php程序設(shè)計有一定幫助作用。
相關(guān)文章
Yii模型操作之criteria查找數(shù)據(jù)庫的方法
這篇文章主要介紹了Yii模型操作之criteria查找數(shù)據(jù)庫的方法,結(jié)合實例形式分析了Yii模型中criteria的實例化與查詢操作相關(guān)技巧,需要的朋友可以參考下2016-07-07Yii2結(jié)合Workerman的websocket示例詳解
這篇文章主要給大家介紹了關(guān)于Yii2結(jié)合Workerman的websocket的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧2018-09-09php使用函數(shù)pathinfo()、parse_url()和basename()解析URL
眾所周知在PHP中函數(shù)pathinfo()、parse_url()和basename(),這三個都是解析URL的函數(shù),但是也存在一些區(qū)別,下面列舉了一些實例,通過實例更容易理解這三個函數(shù)的使用方法和技巧,有需要的朋友可以參考借鑒,感興趣的朋友們下面來一起學習學習吧。2016-11-11