Пример #1
0
 /**
  * Setup view
  *
  * @return void
  */
 public function before()
 {
     if (empty($this->template)) {
         // Generate a template name if one wasn't set.
         $this->template = str_replace('_', DIRECTORY_SEPARATOR, $this->request->controller) . DIRECTORY_SEPARATOR . $this->request->action;
         if (!empty($this->request->directory)) {
             $this->template = $this->request->directory . DIRECTORY_SEPARATOR . $this->template;
         }
     }
     if ($this->auto_render) {
         // Load the twig template.
         $this->template = Twig::factory($this->template, $this->environment);
         // Return the twig environment
         $this->environment = $this->template->environment();
     }
     return parent::before();
 }
Пример #2
0
 /**
  * Setup view
  *
  * @return void
  */
 public function __construct(Request $request, Response $response)
 {
     parent::__construct($request, $response);
     if (empty($this->template)) {
         // Generate a template name if one wasn't set.
         $this->template = str_replace('_', DIRECTORY_SEPARATOR, $this->request->controller()) . DIRECTORY_SEPARATOR . $this->request->action();
         $directory = $this->request->directory();
         if (!empty($directory)) {
             $this->template = $this->request->directory() . DIRECTORY_SEPARATOR . $this->template;
         }
     }
     if ($this->auto_render) {
         // Load the twig template.
         $this->template = Twig::factory($this->template, $this->environment);
         // Return the twig environment
         $this->environment = $this->template->environment();
     }
 }
Пример #3
0
 public function render($file = null)
 {
     if ($file !== NULL) {
         $this->set_filename($file);
     }
     if (empty($this->_file)) {
         throw new Twig_Exception('You must set the file to use within your view before rendering');
     }
     // Get environment
     $twig = Twig::environment();
     // Globals
     if (!empty(Twig::$_global_data)) {
         foreach (Twig::$_global_data as $name => $value) {
             $twig->addGlobal($name, $value);
         }
     }
     // Return a rendered view
     return $twig->render($this->_file, $this->_data);
 }