Name
fetch() 鈥 鍙栧緱杈撳嚭鍐呭
璇存槑
string聽fetch(string聽template,
聽聽聽聽聽聽聽聽聽聽聽聽聽string聽cache_id,
聽聽聽聽聽聽聽聽聽聽聽聽聽string聽compile_id);
璇ュ嚱鏁板皢鍙栧緱涓涓ā鏉胯緭鍑虹殑鍐呭锛岃屼笉鏄鏄剧ず鍑烘潵銆
璇ュ嚱鏁伴渶瑕佹寚瀹氫竴涓悎娉曠殑妯℃澘璧勬簮鐨勭被鍨嬪拰璺緞銆
绗簩涓彲閫夌殑鍙傛暟$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.21.聽fetch()
<?php include('Smarty.class.php'); $smarty = new Smarty; $smarty->setCaching(true); // 鎸夌収URL鏉D5鐢熸垚涓涓壒瀹氱殑缂撳瓨ID $cache_id = md5($_SERVER['REQUEST_URI']); // 鎹曡幏杈撳嚭 $output = $smarty->fetch('index.tpl', $cache_id); // 澶勭悊杈撳嚭鐨勫唴瀹 echo $output; ?>
Example聽14.22.聽鐢╢etch()鏉ュ彂閭欢
email_body.tpl
妯℃澘鐨勫唴瀹癸細
Dear {$contact_info.name}, Welcome and thank you for signing up as a member of our user group. Click on the link below to login with your user name of '{$contact_info.username}' so you can post in our forums. {$login_url} List master {textformat wrap=40} This is some long-winded disclaimer text that would automatically get wrapped at 40 characters. This helps make the text easier to read in mail programs that do not wrap sentences for you. {/textformat}
璇HP鑴氭湰浣跨敤浜哖HP鐨
mail()
鍑芥暟銆
<?php // 浠庢暟鎹簱鎴栧叾浠栨潵婧愯幏鍙栧埌$contact_info $smarty->assign('contact_info',$contact_info); $smarty->assign('login_url',"http://{$_SERVER['SERVER_NAME']}/login"); mail($contact_info['email'], 'Thank You', $smarty->fetch('email_body.tpl')); ?>
鍙傝
{fetch}
display()
,
{eval}
,
鍜
templateExists()
.