Name
registerPlugin() 鈥 娉ㄥ唽鎻掍欢
璇存槑
void聽registerPlugin(string聽type,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽string聽name,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽mixed聽callback,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽bool聽cacheable,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽mixed聽cache_attrs);
璇ュ嚱鏁板皢浠ユ彃浠剁殑褰㈠紡鏉ユ敞鍐屽嚱鏁版垨鑰呮柟娉曘 鍙傛暟濡備笅锛
type
defines the type of the plugin. Valid values are "function", "block", "compiler" and "modifier".name
defines the name of the plugin.-
callback
defines the PHP callback. it can be either:A string containing the function
name
An array of the form
array(&$object, $method)
with&$object
being a reference to an object and$method
being a string containing the method-nameAn array of the form
array($class, $method)
with$class
being the class name and$method
being a method of the class.
澶у鏁版儏鍐典笅
cacheable
鍜cache_attrs
鍙鐪佺暐銆 鍙傝缂撳瓨鑳藉姏璁剧疆瀹冧滑鐨勫笺
Example聽14.39.聽娉ㄥ唽鍑芥暟
<?php $smarty->registerPlugin("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"}
Example聽14.40.聽娉ㄥ唽鍧楀嚱鏁
<?php // 鍑芥暟瀹氫箟 function do_translation ($params, $content, $smarty, &$repeat, $template) { if (isset($content)) { $lang = $params["lang"]; // 杩欓噷鍙互鏀剧疆缈昏瘧 $content 鐨勪唬鐮 return $translation; } } // 娉ㄥ唽鍒癝marty $smarty->registerPlugin("block","translate", "do_translation"); ?>
妯℃澘涓細
{translate lang="br"}Hello, world!{/translate}
Example聽14.41.聽娉ㄥ唽淇グ鍣
<?php // 鎴戜滑灏哖HP鐨剆tripslashes鍑芥暟鏄犲皠鎴愪竴涓猄marty鐨勪慨楗板櫒 $smarty->registerPlugin("modifier","ss", "stripslashes"); ?>
妯℃澘涓彲浣跨敤ss
鏉ヨ繃婊ゅ弽鏂滅嚎銆
<?php {$var|ss} ?>
鍙傝
unregisterPlugin()
,
鎻掍欢鍑芥暟,
鍧楀嚱鏁,
缂栬瘧鍑芥暟,
鍜
淇グ鍣銆