Smarty自定义函数 用smarty编写自己地函数

jackxiang 2009-4-14 17:33 | |
//程序中

$smarty->register_function('asc','asc_num');

//函数地定义

function asc_num($params){
    extract($params);    
    echo chr($num+64);
}

//模板中使用

<{asc num=$smarty.section.loop2.iteration}>


实例:


function insert_left($params, &$smarty) {
  global $FOURAPP;
  $o_app = new AppProx;
  $bRet = $o_app->getUserList(&$objarr, $params['cuseruid']);
  if($bRet) {
    if(is_array($objarr) && count($objarr)>0) {
      $userapplist = array_diff_key($objarr, $FOURAPP);
    } else {
      $userapplist = array();
    }
    $smarty->assign('cuseruid', $params['cuseruid']);
    $smarty->assign('userappnum', count($userapplist));
    $smarty->assign('userapplist', &$userapplist);
    $smarty->assign('fourapp', &$FOURAPP);
  }
  $html = &$smarty->fetch('part/left.html');
  return $html;
}

function insert_top($params,&$smarty){
  $smarty->assign('cuseruid',$params['cuseruid']);
  return $smarty->fetch('part/top.html');
}



HTML调用:

        <div class="SG_wrapall">
            {insert name="top" cuseruid=$uidowner}
        </div>
        <div class="SG_wrap950 pybg">
            <div class="SG_colW13 SG_colFirst">
                {insert name="left" cuseruid=$uidowner}
            </div>







参看:http://movoin.com/index.php/archives/182
http://www.phpx.com/happy/thread-123410-1-1.html


作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/1712/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!


最后编辑: jackxiang 编辑于2009-4-14 18:06
评论列表
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]