本篇內容介紹了“如何實現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-01 php視頻教程 - 2015-08-02 smarty學習 - 2015-08-03
“如何實現smarty簡單模板變量輸出”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。