Beispiel #1
0
 /**
  * Expects a relative url to the template that is to be included as path
  * if extension name is omitted the current extension is used
  *
  * @param string $path
  * @param string $extensionId
  * @param array $data bind additional data to the context
  * @return string
  */
 public static function inc($path, $extensionId = null, $data = array())
 {
     $context = \Context::getInstance();
     if (!is_null($extensionId) && $extensionId != $context->getExtensionName()) {
         // template is within different extension, change context
         $formerContext = $context->getExtensionName();
         $context->setExtensionName($extensionId);
     }
     if (count($data) > 0) {
         \RenderContext::pushContext($data);
     }
     $absPath = self::getTemplate($path, $extensionId);
     if (file_exists($absPath)) {
         include $absPath;
     } else {
         \common_Logger::w('Failed to include "' . $absPath . '" in template');
     }
     // restore context
     if (isset($formerContext)) {
         $context->setExtensionName($formerContext);
     }
 }
 /**
  * Renders the template
  * 
  * @return string the rendered view 
  */
 public function render()
 {
     if (!$this->hasTemplate()) {
         throw new common_Exception('Cannot render without template');
     }
     extract($this->variables);
     RenderContext::pushContext($this->variables);
     ob_start();
     include $this->template;
     $returnValue = ob_get_contents();
     ob_end_clean();
     //clean the extracted variables
     foreach ($this->variables as $key => $name) {
         unset(${$key});
     }
     RenderContext::popContext();
     return $returnValue;
 }