SP的模板函数

#1 xpp1000

我想写一个高级的模版函数,向DEDE一样的,通过一个函数标签输入一个循环数组,可是smarty返回的都是只有一个固定值的函数,能做一个像foreach一样的函数吗,main的值可以通过参数得到的

2013-11-24 23:03:14

#2 xpp1000

就是像帝国的灵动标签一样,<{info table='表名' cond='条件' limt='限制条件' item=one}>
<{$one.title}>
<{/info}>这样的,或者
这个函数把值传给mian
<{foreach from=$main item=one}>
<{$one.title}>
<{/foreach}>

2013-11-24 23:41:18

#3 xpp1000

问题已解决,在Speedphp中的smarty文件中plugins中添加一个function.load_data.php的函数,函数内容如下 ,function smarty_function_load_data($params, &$smarty)
{
  $table=$params['table'] ;
$sp=spClass("$table");
$where=$params['where'];
$limit=$params['limit'];
$rs=$sp->findAll($where,null,null,"$limit");
    //var_dump($params);
    if (!empty($params['assign'])) {
        $smarty->assign($params['assign'], $rs);
    }

}
,然后在模版中调用方法。
   <{load_data assign="lists" table="link" where="`id`<100" limit=10}>
             <{foreach from=$lists item=one}>
                    
                                 <{/foreach}>
实现了我想要的功能,不知道这样写规不规范,还有如果用spAddViewFunction注册一直报错,这个函数如何改写才可以用spAddViewFunction

2013-11-25 00:24:01

#4 jake

你需要使用smarty的块函数,http://www.speedphp.com/smarty/plugins.block.functions.html

smarty的内容都在手册里面了。

spAddViewFunction是注册普通的函数,不能注册块函数。

2013-11-25 08:35:06

#5 拓文

xpp1000 发表于 2013-11-25 00:24
问题已解决,在Speedphp中的smarty文件中plugins中添加一个function.load_data.php的函数,函数内容如下 , ...
应该是规范的,smarty插件就是这样。

2014-07-15 02:41:01