Smartyの拡張 Plugin[Type:modifier]

Smartyは、Smartyの機能を拡張するためプラグインを作成することができます。
プラグインタイプmodifierは、変数の修正子(Variable Modifiers)にあたります。

ここでは、変数の修正子(実はプラグイン)であるcatを参考にしてみます。

catプラグイン

プラグインには、命名規則があります。参照:Smartyの拡張 Plugin[Type:function]

タイプmodifierは、与えられた値に何らかの変更を与えて出力します。
タイプmodifierは、処理の結果を返す必要があります。

phpのソースとテンプレートの記述は、次のようになります。

<?php    
$smarty = new Smarty;
$smarty->assign('articleTitle', "Psychics predict world didn't end");
$smarty->display('index.tpl');
?> 


{$articleTitle|cat:" yesterday."}

catプラグインの第一引数に渡されるのがプラグインで影響を受ける値です。
catプラグインの場合、第二引数に連結する文字列を受け取ります。

function smarty_modifier_cat($string, $cat)
{
    return $string . $cat;
}

第二引数以降へ値を渡すには、テンプレート側で:(コロン)で区切って複数値を指定します。

[an error occurred while processing this directive]