Name
display() 鈥 鏄剧ず
璇存槑
void聽display(string聽template,
聽聽聽聽聽聽聽聽聽聽聽聽聽string聽cache_id,
聽聽聽聽聽聽聽聽聽聽聽聽聽string聽compile_id);
鏄剧ず妯℃澘銆傚鏋滃笇鏈涜繑鍥炶屽苟闈炴樉绀哄綋鍓嶆ā鏉跨殑鍐呭锛岃浣跨敤fetch()
銆
璇ュ嚱鏁伴渶瑕佹寚瀹氫竴涓悎娉曠殑妯℃澘璧勬簮鐨勭被鍨嬪拰璺緞銆
绗簩涓彲閫夌殑鍙傛暟$cache_id
璁剧疆缂撳瓨锛岃鎯呭弬瑙
缂撳瓨銆
As an optional third parameter, you can pass a
$compile_id
.
This is in the event that you want to compile different versions of
the same template, such as having separate templates compiled
for different languages. You can
also set the
$compile_id
variable once instead of passing
this to each call to this function.
Example聽14.19.聽display()
<?php include(SMARTY_DIR.'Smarty.class.php'); $smarty = new Smarty(); $smarty->setCaching(true); // 浠呭湪缂撳瓨涓嶅瓨鍦ㄧ殑鏃跺欒皟鐢 if(!$smarty->isCached('index.tpl')) { // 鏁版嵁 $address = '245 N 50th'; $db_data = array( 'City' => 'Lincoln', 'State' => 'Nebraska', 'Zip' => '68502' ); $smarty->assign('Name', 'Fred'); $smarty->assign('Address', $address); $smarty->assign('data', $db_data); } // 鏄剧ず $smarty->display('index.tpl'); ?>
Example聽14.20.聽鍏朵粬 display() 鐨勭ず渚
鐢妯℃澘璧勬簮鐨勬柟寮忔潵鏄剧ず涓嶅湪
$template_dir
鐩綍涓嬬殑妯℃澘銆
<?php // 缁濆璺緞 $smarty->display('/usr/local/include/templates/header.tpl'); // 缁濆璺緞锛堜娇鐢╢ile://锛 $smarty->display('file:/usr/local/include/templates/header.tpl'); // windows鐜鐨勭粷瀵硅矾寰勶紙鍔″繀鏄痜ile:寮澶达級 $smarty->display('file:C:/www/pub/templates/header.tpl'); // 鏉ヨ嚜妯℃澘璧勬簮搴揹b $smarty->display('db:header.tpl'); ?>
鍙傝 fetch()
鍜
templateExists()
.