你看看手册中的示例// function declaration function do_translation ($params, $content, $smarty, &$repeat, $template) { if (isset($content)) { $lang = $params["lang"]; // do some translation with $content return $translation; } }// register with smarty $smarty->registerPlugin("block","translate", "do_translation"); {translate lang="br"}Hello, world!{/translate}
block方式的会执行两次。通过 if (isset($content)) {,做了判断所以只执行了一次。 http://www.itlearner.com/code/smarty_cn/plugins.block.functions.html
http://www.xuandun.net/173/
function demotest($params) {
extract($params);//获取参数a与b了
echo $a.$b;//输出
}
{demo a="2" b="test"}
function do_translation ($params, $content, $smarty, &$repeat, $template)
{
if (isset($content)) {
$lang = $params["lang"];
// do some translation with $content
return $translation;
}
}// register with smarty
$smarty->registerPlugin("block","translate", "do_translation");
{translate lang="br"}Hello, world!{/translate}
http://www.itlearner.com/code/smarty_cn/plugins.block.functions.html
function test2($arr,$content){
print_r($arr);
//$html = "<div style='font-size:".$arr["size"]."px;color:".$arr["color"]."'>".$content."</div>";
//return $html;
}$smarty->registerPlugin("block","test2","test2");<{test2 size="30" color="#ff0000"}>Hello World<{/test2}>
输出:
Array ( [size] => 30 [color] => #ff0000 ) Array ( [size] => 30 [color] => #ff0000 )