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_function() — テンプレート関数プラグインを動的に登録します。

説明

void register_function(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.23. register_function()


<?php
$smarty->register_function('date_now', 'print_current_date');

function print_current_date($params, &$smarty)
{
  if(empty($params['format'])) {
    $format = "%b %e, %Y";
  } else {
    $format = $params['format'];
  }
  return strftime($format,time());
}
?>

   

テンプレート


{date_now}

{* 異なるフォーマット *}
{date_now format="%Y/%m/%d"}


unregister_function() および テンプレート関数プラグイン の項も参照してください。

Comments
No comments for this page.

Advertisement

Sponsors [info]

Sponsors