/**
  * 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;
 }
Exemple #2
0
 /**
  * @test
  */
 public function testGetTemplateIdentifierReturnsSourceChecksumWithControllerAndActionAndFormat()
 {
     $instance = new TemplatePaths();
     $instance->setTemplateSource('foobar');
     $this->assertEquals('source_8843d7f92416211de9ebb963ff4ce28125932878_DummyController_dummyAction_html', $instance->getTemplateIdentifier('DummyController', 'dummyAction'));
 }