/** * Renders a partial. * * @param string $partialName * @param string $sectionName * @param array $variables * @return string */ public function renderPartial($partialName, $sectionName, array $variables) { if (!isset($this->partialIdentifierCache[$partialName])) { $this->partialIdentifierCache[$partialName] = $this->getPartialIdentifier($partialName); } $partialIdentifier = $this->partialIdentifierCache[$partialName]; if ($this->templateCompiler->has($partialIdentifier)) { $parsedPartial = $this->templateCompiler->get($partialIdentifier); } else { $this->templateParser->setConfiguration($this->buildParserConfiguration()); $parsedPartial = $this->templateParser->parse($this->getPartialSource($partialName)); if ($parsedPartial->isCompilable()) { $this->templateCompiler->store($partialIdentifier, $parsedPartial); } } /** @var $variableContainer TemplateVariableContainer **/ $variableContainer = $this->objectManager->get(\TYPO3\Fluid\Core\ViewHelper\TemplateVariableContainer::class, $variables); $renderingContext = clone $this->getCurrentRenderingContext(); $renderingContext->injectTemplateVariableContainer($variableContainer); $this->startRendering(self::RENDERING_PARTIAL, $parsedPartial, $renderingContext); if ($sectionName !== null) { $output = $this->renderSection($sectionName, $variables); } else { $output = $parsedPartial->render($renderingContext); } $this->stopRendering(); return $output; }
/** * 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, the view of the specified action will be rendered instead. Default is the action specified in the Request object * @return string Rendered Template * @api */ public function render($actionName = NULL) { $this->templateParser->setConfiguration($this->buildParserConfiguration()); $templateIdentifier = $this->getTemplateIdentifier($actionName); if ($this->templateCompiler->has($templateIdentifier)) { $parsedTemplate = $this->templateCompiler->get($templateIdentifier); } else { $parsedTemplate = $this->templateParser->parse($this->getTemplateSource($actionName)); if ($parsedTemplate->isCompilable()) { $this->templateCompiler->store($templateIdentifier, $parsedTemplate); } } if ($parsedTemplate->hasLayout()) { $layoutName = $parsedTemplate->getLayoutName($this->baseRenderingContext); $layoutIdentifier = $this->getLayoutIdentifier($layoutName); if ($this->templateCompiler->has($layoutIdentifier)) { $parsedLayout = $this->templateCompiler->get($layoutIdentifier); } else { $parsedLayout = $this->templateParser->parse($this->getLayoutSource($layoutName)); if ($parsedLayout->isCompilable()) { $this->templateCompiler->store($layoutIdentifier, $parsedLayout); } } $this->startRendering(self::RENDERING_LAYOUT, $parsedTemplate, $this->baseRenderingContext); $output = $parsedLayout->render($this->baseRenderingContext); $this->stopRendering(); } else { $this->startRendering(self::RENDERING_TEMPLATE, $parsedTemplate, $this->baseRenderingContext); $output = $parsedTemplate->render($this->baseRenderingContext); $this->stopRendering(); } return $output; }
/** * Renders a section on its own, i.e. without the a surrounding template. * * In this case, we just emulate that a surrounding (empty) layout exists, * and trigger the normal rendering flow then. * * @param string $sectionName Name of section to render * @param array $variables The variables to use * @param boolean $ignoreUnknown Ignore an unknown section and just return an empty string * @return string rendered template for the section */ protected function renderStandaloneSection($sectionName, array $variables = NULL, $ignoreUnknown = FALSE) { $templateIdentifier = $this->getTemplateIdentifier(); if ($this->templateCompiler->has($templateIdentifier)) { $parsedTemplate = $this->templateCompiler->get($templateIdentifier); } else { $this->templateParser->setConfiguration($this->buildParserConfiguration()); $parsedTemplate = $this->templateParser->parse($this->getTemplateSource()); if ($parsedTemplate->isCompilable()) { $this->templateCompiler->store($templateIdentifier, $parsedTemplate); } } $this->baseRenderingContext->setControllerContext($this->controllerContext); $this->startRendering(self::RENDERING_LAYOUT, $parsedTemplate, $this->baseRenderingContext); $output = $this->renderSection($sectionName, $variables, $ignoreUnknown); $this->stopRendering(); return $output; }