トランザクショントークンの続き
いちいちhiddenフィールドを書くのは面倒だし、項目名を間違える可能性があるのでSmartyのpluginを作ってみた。これもMoony 0.8.1で追加予定。使い方はこんな感じ:
{moony_token xhtml=true}
テンプレートのform内に上記のように記述すると、以下のように展開される。
<input type="hidden" name="moony_transaction_token" value="..." />
以下ソース:
function smarty_function_moony_token($params, &$smarty) { $is_xhtml = false; if (isset($params['xhtml']) && $params['xhtml'] === true) { $is_xhtml = true; } $name = MOONY_TRANSACTION_TOKEN_NAME; $value = $smarty->_tpl_vars[$name]; $content = "<input type=\"hidden\" name=\"${name}\" value=\"${value}\""; $content .= $is_xhtml ? ' />' : '>'; echo $content; }