Advertisement
Guest User

Template Class

a guest
Nov 4th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. class Template
  2. {
  3. private $params = array();
  4. private $template_file;
  5.  
  6. public function __construct()
  7. {
  8. global $CONFIG;
  9. $this->SetParameter('site_path', $CONFIG['SITE']['PATH']);
  10. $this->SetParameter('web_gallery', $CONFIG['SITE']['DATA']);
  11.  
  12. $this->SetParameter('full_name', $CONFIG['SITE']['FULL']);
  13. $this->SetParameter('short_name', $CONFIG['SITE']['NAME']);
  14. }
  15.  
  16. private function Display($value)
  17. {
  18. $content = ROOT_PATH."/templates/".$value.".html";
  19.  
  20. ob_start();
  21. require_once($content);
  22. $content = ob_get_contents();
  23. ob_end_clean();
  24.  
  25. foreach($this->params as $param => $value)
  26. {
  27. $content = str_ireplace('{$' . $param . '}', $value, $content);
  28. }
  29.  
  30. echo $content;
  31. }
  32.  
  33. public function SetParameter($param, $value)
  34. {
  35. $this->params[$param] = $value;
  36. }
  37.  
  38. public function AddTemplate($template_file)
  39. {
  40. return $this->Display($template_file);
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement