{capture}
{capture} は、タグの間のテンプレートの出力を集め、
それをブラウザに表示する代わりに変数に受け渡します。
{capture name='foo'} と {/capture}
の間のあらゆるコンテンツは、name
属性で指定した変数に格納されます。
キャプチャされたコンテンツは、特別な変数
$smarty.capture.foo
("foo" は name 属性で指定した変数) によって利用できます。
name 属性を指定しない場合は "default"
が使われ、$smarty.capture.default
のようになります。
{capture}'s はネスト可能です。
例 7-1. name 属性を使用した {capture} {* コンテンツが表示されない限り、テーブルの行を表示しません *}
{capture name=banner}
{include file='get_banner.tpl'}
{/capture}
{if $smarty.capture.banner ne ''}
<div id="banner">{$smarty.capture.banner}</div>
{/if} |
|
例 7-2. {capture} をテンプレート変数に格納 この例は、
{popup}
関数の使用法を示すものです。 {capture name=some_content assign=popText}
The server is {$smarty.server.SERVER_NAME|upper} at {$smarty.server.SERVER_ADDR}<br>
Your ip is {$smarty.server.REMOTE_ADDR}.
{/capture}
<a href="#" {popup caption='Server Info' text=$popText}>help</a> |
|
$smarty.capture、
{eval}、
{fetch}、
fetch()
および {assign}
も参照してください。