2 namespace TYPO3\CMS\Fluid\View;
83 $this->templateCompiler->setTemplateCache(\TYPO3\CMS\Core\Utility\
GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache(
'fluid_template'));
94 $this->baseRenderingContext = $renderingContext;
95 $this->baseRenderingContext->getViewHelperVariableContainer()->setView($this);
96 $this->controllerContext = $renderingContext->getControllerContext();
126 $templateVariableContainer = $this->baseRenderingContext->getTemplateVariableContainer();
127 if ($templateVariableContainer->exists($key)) {
128 $templateVariableContainer->remove($key);
130 $templateVariableContainer->add($key, $value);
144 $templateVariableContainer = $this->baseRenderingContext->getTemplateVariableContainer();
145 foreach ($values as $key => $value) {
146 if ($templateVariableContainer->exists($key)) {
147 $templateVariableContainer->remove($key);
149 $templateVariableContainer->add($key, $value);
162 public function render($actionName = null)
164 $this->baseRenderingContext->setControllerContext($this->controllerContext);
168 if ($this->templateCompiler->has($templateIdentifier)) {
169 $parsedTemplate = $this->templateCompiler->get($templateIdentifier);
171 $parsedTemplate = $this->templateParser->parse($this->
getTemplateSource($actionName));
172 if ($parsedTemplate->isCompilable()) {
173 $this->templateCompiler->store($templateIdentifier, $parsedTemplate);
177 if ($parsedTemplate->hasLayout()) {
178 $layoutName = $parsedTemplate->getLayoutName($this->baseRenderingContext);
180 if ($this->templateCompiler->has($layoutIdentifier)) {
181 $parsedLayout = $this->templateCompiler->get($layoutIdentifier);
183 $parsedLayout = $this->templateParser->parse($this->
getLayoutSource($layoutName));
184 if ($parsedLayout->isCompilable()) {
185 $this->templateCompiler->store($layoutIdentifier, $parsedLayout);
188 $this->
startRendering(self::RENDERING_LAYOUT, $parsedTemplate, $this->baseRenderingContext);
189 $output = $parsedLayout->render($this->baseRenderingContext);
192 $this->
startRendering(self::RENDERING_TEMPLATE, $parsedTemplate, $this->baseRenderingContext);
193 $output = $parsedTemplate->render($this->baseRenderingContext);
209 public function renderSection($sectionName, array $variables, $ignoreUnknown =
false)
214 $renderingTypeOnNextLevel = self::RENDERING_TEMPLATE;
216 $variableContainer = $this->objectManager->get(\TYPO3\CMS\
Fluid\Core\ViewHelper\TemplateVariableContainer::class, $variables);
217 $renderingContext = clone $renderingContext;
218 $renderingContext->injectTemplateVariableContainer($variableContainer);
224 if ($parsedTemplate->isCompiled()) {
225 $methodNameOfSection =
'section_' . sha1($sectionName);
226 if ($ignoreUnknown && !method_exists($parsedTemplate, $methodNameOfSection)) {
229 $this->
startRendering($renderingTypeOnNextLevel, $parsedTemplate, $renderingContext);
230 $output = $parsedTemplate->{$methodNameOfSection}($renderingContext);
233 $sections = $parsedTemplate->getVariableContainer()->get(
'sections');
234 if (!array_key_exists($sectionName, $sections)) {
235 $controllerObjectName = $this->controllerContext->getRequest()->getControllerObjectName();
236 if ($ignoreUnknown) {
239 throw new \TYPO3\CMS\Fluid\View\Exception\InvalidSectionException(sprintf(
'Could not render unknown section "%s" in %s used by %s.', $sectionName, get_class($this), $controllerObjectName), 1227108982);
242 $section = $sections[$sectionName];
244 $renderingContext->getViewHelperVariableContainer()->add(\TYPO3\CMS\Fluid\ViewHelpers\SectionViewHelper::class,
'isCurrentlyRenderingSection',
'TRUE');
246 $this->
startRendering($renderingTypeOnNextLevel, $parsedTemplate, $renderingContext);
247 $output = $section->evaluate($renderingContext);
263 public function renderPartial($partialName, $sectionName, array $variables)
265 $partialNameWithFormat = $partialName .
'.' . $this->controllerContext->getRequest()->getFormat();
266 if (!isset($this->partialIdentifierCache[$partialNameWithFormat])) {
267 $this->partialIdentifierCache[$partialNameWithFormat] = $this->getPartialIdentifier($partialName);
269 $partialIdentifier = $this->partialIdentifierCache[$partialNameWithFormat];
271 if ($this->templateCompiler->has($partialIdentifier)) {
272 $parsedPartial = $this->templateCompiler->get($partialIdentifier);
274 $parsedPartial = $this->templateParser->parse($this->getPartialSource($partialName));
275 if ($parsedPartial->isCompilable()) {
276 $this->templateCompiler->store($partialIdentifier, $parsedPartial);
280 $variableContainer = $this->objectManager->get(\TYPO3\CMS\
Fluid\Core\ViewHelper\TemplateVariableContainer::class, $variables);
281 $renderingContext = clone $this->getCurrentRenderingContext();
282 $renderingContext->injectTemplateVariableContainer($variableContainer);
284 $this->startRendering(self::RENDERING_PARTIAL, $parsedPartial, $renderingContext);
285 if ($sectionName !== null) {
286 $output = $this->renderSection($sectionName, $variables);
288 $output = $parsedPartial->render($renderingContext);
290 $this->stopRendering();
301 protected function ucFileNameInPath($templatePath)
303 if (strpos($templatePath,
'/') > 0) {
304 $pathParts = explode(
'/', $templatePath);
305 $index = count($pathParts) - 1;
306 $pathParts[$index] = ucfirst($pathParts[$index]);
308 $upperCasedTemplateName = implode(
'/', $pathParts);
310 $upperCasedTemplateName = ucfirst($templatePath);
312 return $upperCasedTemplateName;
321 protected function testFileExistence($filePath)
323 return is_file($filePath);
333 abstract protected function getTemplateIdentifier($actionName = null);
343 abstract protected function getTemplateSource($actionName = null);
352 abstract protected function getLayoutIdentifier($layoutName =
'Default');
366 abstract protected function getLayoutSource($layoutName =
'Default');
375 abstract protected function getPartialIdentifier($partialName);
384 abstract protected function getPartialSource($partialName);
391 protected function buildParserConfiguration()
393 $parserConfiguration = $this->objectManager->get(\TYPO3\CMS\
Fluid\Core\Parser\Configuration::class);
394 if ($this->controllerContext->getRequest()->getFormat() ===
'html') {
395 $parserConfiguration->addInterceptor($this->objectManager->get(\TYPO3\CMS\
Fluid\Core\Parser\Interceptor\Escape::class));
397 return $parserConfiguration;
408 protected function startRendering($type, \TYPO3\CMS\
Fluid\Core\Parser\ParsedTemplateInterface $parsedTemplate, \TYPO3\CMS\
Fluid\Core\Rendering\
RenderingContextInterface $renderingContext)
410 array_push($this->renderingStack, array(
'type' => $type,
'parsedTemplate' => $parsedTemplate,
'renderingContext' => $renderingContext));
419 protected function stopRendering()
421 array_pop($this->renderingStack);
429 protected function getCurrentRenderingType()
431 $currentRendering = end($this->renderingStack);
432 return $currentRendering[
'type'];
440 protected function getCurrentParsedTemplate()
442 $currentRendering = end($this->renderingStack);
443 return $currentRendering[
'parsedTemplate'];
451 protected function getCurrentRenderingContext()
453 $currentRendering = end($this->renderingStack);
454 return $currentRendering[
'renderingContext'];
467 public function canRender(\TYPO3\CMS\Extbase\Mvc\Controller\
ControllerContext $controllerContext)