Esempio n. 1
0
 /**
  * Loads the template source and render the template.
  * If "layoutName" is set in a PostParseFacet callback, it will render the file with the given layout.
  *
  * @param string $actionName If set, this action's template will be rendered instead of the one defined in the context.
  * @return string Rendered Template
  * @api
  */
 public function render($actionName = NULL)
 {
     $this->templateParser->setConfiguration($this->buildParserConfiguration());
     $this->templateParser->setVariableProvider($this->baseRenderingContext->getVariableProvider());
     $this->templateParser->setViewHelperResolver($this->viewHelperResolver);
     $this->baseRenderingContext->setViewHelperResolver($this->viewHelperResolver);
     $controllerName = $this->baseRenderingContext->getControllerName();
     if (!$actionName) {
         $actionName = $this->baseRenderingContext->getControllerAction();
     }
     $actionName = ucfirst($actionName);
     if (empty($templateIdentifier)) {
         $templateIdentifier = $this->templatePaths->getTemplateIdentifier($controllerName, $actionName);
     }
     $parsedTemplate = $this->getOrParseAndStoreTemplate($templateIdentifier, function ($parent, TemplatePaths $paths) use($controllerName, $actionName) {
         return $paths->getTemplateSource($controllerName, $actionName);
     });
     $parsedTemplate->addCompiledNamespaces($this->baseRenderingContext);
     if (!$parsedTemplate->hasLayout()) {
         $this->startRendering(self::RENDERING_TEMPLATE, $parsedTemplate, $this->baseRenderingContext);
         $output = $parsedTemplate->render($this->baseRenderingContext);
         $this->stopRendering();
     } else {
         $layoutName = $parsedTemplate->getLayoutName($this->baseRenderingContext);
         $layoutIdentifier = $this->templatePaths->getLayoutIdentifier($layoutName);
         $parsedLayout = $this->getOrParseAndStoreTemplate($layoutIdentifier, function ($parent, TemplatePaths $paths) use($layoutName) {
             return $paths->getLayoutSource($layoutName);
         });
         $this->startRendering(self::RENDERING_LAYOUT, $parsedTemplate, $this->baseRenderingContext);
         $output = $parsedLayout->render($this->baseRenderingContext);
         $this->stopRendering();
     }
     return $output;
 }
Esempio n. 2
0
 /**
  * Loads the template source and render the template.
  * If "layoutName" is set in a PostParseFacet callback, it will render the file with the given layout.
  *
  * @param string|null $actionName If set, this action's template will be rendered instead of the one defined in the context.
  * @return string Rendered Template
  * @api
  */
 public function render($actionName = null)
 {
     $controllerName = $this->baseRenderingContext->getControllerName();
     $templateParser = $this->baseRenderingContext->getTemplateParser();
     $templatePaths = $this->baseRenderingContext->getTemplatePaths();
     if ($actionName === null) {
         $actionName = $this->baseRenderingContext->getControllerAction();
     }
     $actionName = ucfirst($actionName);
     try {
         $parsedTemplate = $templateParser->getOrParseAndStoreTemplate($templatePaths->getTemplateIdentifier($controllerName, $actionName), function ($parent, TemplatePaths $paths) use($controllerName, $actionName) {
             return $paths->getTemplateSource($controllerName, $actionName);
         });
     } catch (PassthroughSourceException $error) {
         return $error->getSource();
     }
     $parsedTemplate->addCompiledNamespaces($this->baseRenderingContext);
     if (!$parsedTemplate->hasLayout()) {
         $this->startRendering(self::RENDERING_TEMPLATE, $parsedTemplate, $this->baseRenderingContext);
         $output = $parsedTemplate->render($this->baseRenderingContext);
         $this->stopRendering();
     } else {
         $layoutName = $parsedTemplate->getLayoutName($this->baseRenderingContext);
         try {
             $parsedLayout = $templateParser->getOrParseAndStoreTemplate($templatePaths->getLayoutIdentifier($layoutName), function ($parent, TemplatePaths $paths) use($layoutName) {
                 return $paths->getLayoutSource($layoutName);
             });
         } catch (PassthroughSourceException $error) {
             return $error->getSource();
         }
         $this->startRendering(self::RENDERING_LAYOUT, $parsedTemplate, $this->baseRenderingContext);
         $output = $parsedLayout->render($this->baseRenderingContext);
         $this->stopRendering();
     }
     return $output;
 }