Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.28 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\CommonModule\Components;
  4.  
  5. use Nette,
  6.     App;
  7.  
  8.  
  9. /**
  10.  * @author Martin Konečný
  11.  */
  12. class AjaxTemplate extends BaseControl
  13. {
  14.    
  15.     /** @var string */
  16.     private $templateName;
  17.  
  18.     /** @var array */
  19.     private $templateParams;
  20.    
  21.    
  22.     /**
  23.      * @param string
  24.      * @param array
  25.      */
  26.     public function __construct($templateName, $templateParams = array())
  27.     {
  28.         parent::__construct();
  29.        
  30.         $this->templateName = $templateName;
  31.         $this->templateParams = (array) $templateParams;
  32.     }
  33.    
  34.    
  35.     /**
  36.      * @param string
  37.      * @param array
  38.      */
  39.     public static function create($templateName, $templateParams = array())
  40.     {
  41.         $self = new self($templateName, $templateParams);
  42.        
  43.         return $self->getHtml();
  44.     }
  45.    
  46.    
  47.     /**
  48.      * @return string
  49.      */
  50.     public function getHtml()
  51.     {
  52.         $this->template->setParameters($this->templateParams);
  53.         $this->template->setFile(__DIR__ . "/templates/{$this->templateName}.latte");
  54.        
  55.         $result = (string) $this->template;
  56.        
  57.         return $result;
  58.     }
  59.    
  60.    
  61.     /**
  62.      * @param string
  63.      * @param callable
  64.      */
  65.     public function addFilter($name, $callable)
  66.     {
  67.         $this->template->addFilter($name, $callable);
  68.     }
  69.    
  70.    
  71.     /**
  72.      * @return string
  73.      */
  74.     public function __toString()
  75.     {
  76.         return $this->getHtml();
  77.     }
  78.    
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement