smarty簡單模板變數輸出方法[原創]_php執行個體

來源:互聯網
上載者:User

本文簡單講述了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程式設計有一定協助作用。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.