Smarty{call}
組み込み関数は、{function} タグで定義されたテンプレート関数を呼び出すことができます。ここで、プラグイン内の関数名しか知らないため、プラグイン関数内でテンプレート関数を呼び出す必要があります。
プラグイン機能:
<?php
$smarty->registerPlugin('function', 'form_label', 'renderFormLabel');
function renderFormLabel($form, \Smarty_Internal_Template $template) {
// find out which function to call based on the available ones
$function = lookupTemplateFunction($template);
$args = $form->getVariables();
// How to call the Smarty template function with the given $args?
// $html = $template->smarty->???($args);
//return $html;
}
テンプレート:
<form action="submit.php" method="post">
{form_label}
....
</form>
これはSmartyBundleでSymfony2 Formsをサポートするための取り組みです。各フォーム フラグメントは、Smarty 関数によって表されます。フォームのレンダリング方法の一部をカスタマイズするには、ユーザーは適切な関数をオーバーライドするだけです。