Smarty makelink function


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function smarty_function_makelink ($params, $smarty)
  2. {
  3. if(!is_array($smarty->tpl_vars['acces_sites']->value))
  4. {
  5. throw new Exception ("makelink: param 'access_sites' not assigned");
  6. return;
  7. }
  8.  
  9. if (empty($params['link']))
  10. {
  11. throw new Exception ("makelink: param 'link' not defined");
  12. return;
  13. }
  14.  
  15. if (isset($params['type']))
  16. $type = $params['type'];
  17. else
  18. $type = 'action';
  19.  
  20. $link = $params['link'];
  21.  
  22. if (isset($params['name']))
  23. $name = $params['name'];
  24. else
  25. $name = $link;
  26.  
  27. if($smarty->tpl_vars['acces_sites']->value[$link] == '1')
  28. {
  29. $data = explode("_", $link);
  30. $return = '<a href="'.$smarty->tpl_vars['webroot']->value.'/'.$data[0].'/'.$data[1].'/'.$data[2].'" class="ektab ';
  31. $act = $smarty->tpl_vars['params']->value;
  32. switch ($type)
  33. {
  34. case 'action': $alink = $act['module']."_".$act['controller']."_".$act['action']; break;
  35. case 'controller': $alink = $act['module']."_".$act['controller'].'_index'; break;
  36. case 'module': $alink = $act['module']; break;
  37. }
  38. if($link == $alink) $return .= 'active ';
  39. $return .= '">'.$name.'</a>';
  40. return $return;
  41. }
  42. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.