Get Smarty

Donate

Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Advertisement

Chapter 7. 組み込み関数

Smarty にはいくつかの組み込み関数があります。 これらはテンプレートエンジンにとって必要不可欠なものです。これらと同じ名前の カスタム関数 を作成したり、組み込み関数を修正したりする事はできません。

これらの関数の一部は assign 属性を持っており、 結果を出力せずにここで指定した名前のテンプレート変数に格納します。これは {assign} 関数と似ています。

{capture}

{capture} は、タグの間のテンプレートの出力を集め、 それをブラウザに表示する代わりに変数に受け渡します。 {capture name='foo'}{/capture} の間のあらゆるコンテンツは、name 属性で指定した変数に格納されます。

キャプチャされたコンテンツは、特別な変数 $smarty.capture.foo (fooname 属性で指定した変数) によって利用できます。 name 属性を指定しない場合は default が使われ、$smarty.capture.default のようになります。

{capture}'s はネスト可能です。

属性名 必須 デフォルト 概要
name string no default キャプチャされるブロックの名前
assign string No n/a キャプチャされた出力を割り当てるための変数名

注意

{insert} の出力をキャプチャする際には注意が必要です。 $caching が有効の時に、実行したい {insert} コマンドがもしキャッシュされたコンテンツ内にあるのなら、そのコンテンツはキャプチャされません。

Example 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}

   


Example 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} も参照してください。

Comments
No comments for this page.

Advertisement

Sponsors [info]

Sponsors