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

Name

register_block() — ブロック関数プラグインを動的に登録します。

説明

void register_block(string name,
                    mixed impl,
                    bool cacheable,
                    mixed cache_attrs);

ブロック関数プラグイン を動的に登録します。パラメータには、ブロック関数名とそれを実装する PHP のユーザー定義関数名を渡します。

PHP 関数のコールバック function は、次のいずれかとなります。

  • 関数名を含んだ文字列

  • array(&$object, $method) 形式の配列 (&$object はオブジェクトの参照で、 $method はメソッド名を含む文字列)

  • array($class, $method) という形式の配列 ($class はクラス名であり、 $method はクラスのメソッド)

cacheablecache_attrs はほとんどの場合に省略可能です。これらの正しい使用法についての詳細は、 キャッシュ可能なプラグインの出力の制御 を参照して下さい。

Example 13.22. register_block()


<?php
// 関数の宣言
function do_translation ($params, $content, &$smarty, &$repeat)
{
  if (isset($content)) {
    $lang = $params['lang'];
    // $content においていくつかの変換を行います
    return $translation;
  }
}

// smarty に登録します
$smarty->register_block('translate', 'do_translation');
?>

   

テンプレート


{translate lang='br'}Hello, world!{/translate}

   

unregister_block() および ブロック関数プラグイン のページも参照してください。

Comments
No comments for this page.

Advertisement

Sponsors [info]

Sponsors