smarty簡單模板變量輸出方法
來源:易賢網(wǎng) 閱讀:1019 次 日期:2016-08-15 14:46:54
溫馨提示:易賢網(wǎng)小編為您整理了“smarty簡單模板變量輸出方法”,方便廣大網(wǎng)友查閱!

本文簡單講述了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測試標(biāo)題";

$content="smarty練習(xí)!";

$newstext[]=array("name"=>"php程序測試","date"=>"2015-08-01");

$newstext[]=array("name"=>"php視頻教程","date"=>"2015-08-02");

$newstext[]=array("name"=>"smarty學(xué)習(xí)","date"=>"2015-08-03");

$row=array("標(biāo)題","姓名","年齡");

$smarty->assign("title",$title);

$smarty->assign("row",$row);//一個數(shù)組傳遞多個值

$smarty->assign("shownewstext",$newstext);//二維數(shù)組傳遞多個值

$smarty->assign("content",$content);

$smarty->display('index.htm');

運(yùn)行結(jié)果如下:

測試數(shù)組:標(biāo)題 | 姓名 | 年齡 

--------------------------------------------------------------------------------

測試內(nèi)容為:smarty練習(xí)! 

循環(huán)新聞內(nèi)容為:

php程序測試 - 2015-08-01

php視頻教程 - 2015-08-02

smarty學(xué)習(xí) - 2015-08-03

希望本文所述對大家基于Smarty模板的php程序設(shè)計有一定幫助作用。

更多信息請查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機(jī)網(wǎng)站地址:smarty簡單模板變量輸出方法
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 加入群交流 | 手機(jī)站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65317125(9:00—18:00) 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報警專用圖標(biāo)