去掉这个“ <{/demo}>”?

解决方案 »

  1.   

    木写过插件,这这例子有帮助没?
    http://www.xuandun.net/173/
      

  2.   

    smarty 3.1.7例子没有问题$smarty = new Smarty;$smarty->registerPlugin("function","demo", "demotest");;//制定类型,这里制定是函数调用,指定模板函数名称和php函数名称
    function demotest($params) {
    extract($params);//获取参数a与b了
    echo $a.$b;//输出
    }
    {demo a="2" b="test"}
      

  3.   

    $smarty->registerPlugin("function","demo", "demotest")的确没有问题 我说的是  $smarty->registerPlugin("block","demo", "demotest")再试试
      

  4.   

    你看看手册中的示例// 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}
      

  5.   

    block方式的会执行两次。通过 if (isset($content)) {,做了判断所以只执行了一次。
    http://www.itlearner.com/code/smarty_cn/plugins.block.functions.html
      

  6.   

    block会出现两次,算是smarty的一个bug吧。但不影响使用。
    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 )