{capture}鍙互鎹曡幏鏍囪鑼冨洿鍐呯殑杈撳嚭鍐呭锛屽瓨鍒板彉閲忎腑鑰屼笉鏄剧ず銆
浠讳綍鍦{capture name='foo'} 鍜 {/capture}
涔嬮棿鐨勫唴瀹归兘浼氳鎹曡幏鍒板彉閲忥紝鍙橀噺鍚嶅彲浠ラ氳繃name灞炴ф潵鎸囧畾銆
鎹曡幏鐨勫唴瀹瑰彲浠ラ氳繃$smarty.capture.foo鍙橀噺鏉ヤ娇鐢紝杩欓噷foo鏄缃殑name灞炴с
濡傛灉娌℃湁鎻愪緵name灞炴э紝榛樿鏄鈥default鈥锛屼篃灏辨槸
$smarty.capture.default.
{capture}鍙互琚祵濂椾娇鐢ㄣ
灞炴:
| 鍙傛暟鍚嶇О | 绫诲瀷 | 蹇呴夊弬鏁 | 榛樿鍊 | 璇存槑 |
|---|---|---|---|---|
| name | string | Yes | n/a | 鎹曡幏鍖哄煙鐨勫悕绉 |
| assign | string | No | n/a | 鎹曡幏鍐呭鍚庤祴鍊肩殑鍙橀噺鍚 |
| append | string | No | n/a | 灏嗘崟鑾风殑鍐呭澧炲姞鍒版暟缁勪腑 |
鍙夋爣璁:
| 鍚嶇О | 璇存槑 |
|---|---|
| nocache | 鍏抽棴鎹曡幏鍖哄煙鐨勭紦瀛 |
璀﹀憡
褰撴崟鑾{insert}杈撳嚭鐨勬椂鍊欒灏忓績銆
濡傛灉寮鍚簡$caching骞朵笖
浣犲笇鏈涢氳繃{insert}
鍦ㄧ紦瀛樼殑椤甸潰涓婃樉绀哄姩鎬佸唴瀹癸紝閭d箞浣犳棤娉曟崟鑾疯繖浜涘唴瀹广
Example聽7.21.聽{capture}浣跨敤name灞炴
{* we don't want to print a div tag unless content is displayed *}
{capture name="banner"}
{capture "banner"} {* short-hand *}
{include file="get_banner.tpl"}
{/capture}
{if $smarty.capture.banner ne ""}
<div id="banner">{$smarty.capture.banner}</div>
{/if}
Example聽7.22.聽{capture} 鎹曡幏鍐呭鍒板彉閲
涓嬮潰鏄痗apture鍑芥暟鐨勬紨绀
{capture name=some_content assign=popText}
{capture some_content assign=popText} {* short-hand *}
The server is {$my_server_name|upper} at {$my_server_addr}<br>
Your ip is {$my_ip}.
{/capture}
<a href="#">{$popText}</a>
Example聽7.23.聽{capture} 鎹曡幏鍐呭鍒版暟缁勫彉閲
涓嬮潰渚嬪瓙婕旂ず浜嗗浣曞娆℃崟鑾峰唴瀹癸紝褰㈡垚鏁扮粍銆
{capture append="foo"}hello{/capture}I say just {capture append="foo"}world{/capture}
{foreach $foo as $text}{$text} {/foreach}
杈撳嚭锛
I say just hello world
鍙傝
$smarty.capture,
{eval},
{fetch},
fetch()
鍜 {assign}.
