82 $this->templateCompiler->setTemplateCache(\
TYPO3\CMS\Core\Utility\
GeneralUtility::makeInstance(
'TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache(
'fluid_template'));
92 $this->baseRenderingContext = $renderingContext;
93 $this->baseRenderingContext->getViewHelperVariableContainer()->setView($this);
94 $this->controllerContext = $renderingContext->getControllerContext();
121 $templateVariableContainer = $this->baseRenderingContext->getTemplateVariableContainer();
122 if ($templateVariableContainer->exists($key)) {
123 $templateVariableContainer->remove($key);
125 $templateVariableContainer->add($key, $value);
138 $templateVariableContainer = $this->baseRenderingContext->getTemplateVariableContainer();
139 foreach ($values as $key => $value) {
140 if ($templateVariableContainer->exists($key)) {
141 $templateVariableContainer->remove($key);
143 $templateVariableContainer->add($key, $value);
156 public function render($actionName = NULL) {
157 $this->baseRenderingContext->setControllerContext($this->controllerContext);
161 if ($this->templateCompiler->has($templateIdentifier)) {
162 $parsedTemplate = $this->templateCompiler->get($templateIdentifier);
164 $parsedTemplate = $this->templateParser->parse($this->
getTemplateSource($actionName));
165 if ($parsedTemplate->isCompilable()) {
166 $this->templateCompiler->store($templateIdentifier, $parsedTemplate);
170 if ($parsedTemplate->hasLayout()) {
171 $layoutName = $parsedTemplate->getLayoutName($this->baseRenderingContext);
173 if ($this->templateCompiler->has($layoutIdentifier)) {
174 $parsedLayout = $this->templateCompiler->get($layoutIdentifier);
176 $parsedLayout = $this->templateParser->parse($this->
getLayoutSource($layoutName));
177 if ($parsedLayout->isCompilable()) {
178 $this->templateCompiler->store($layoutIdentifier, $parsedLayout);
181 $this->
startRendering(self::RENDERING_LAYOUT, $parsedTemplate, $this->baseRenderingContext);
182 $output = $parsedLayout->render($this->baseRenderingContext);
185 $this->
startRendering(self::RENDERING_TEMPLATE, $parsedTemplate, $this->baseRenderingContext);
186 $output = $parsedTemplate->render($this->baseRenderingContext);
202 public function renderSection($sectionName, array $variables, $ignoreUnknown = FALSE) {
206 $renderingTypeOnNextLevel = self::RENDERING_TEMPLATE;
208 $variableContainer = $this->objectManager->get(
'TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TemplateVariableContainer', $variables);
209 $renderingContext = clone $renderingContext;
210 $renderingContext->injectTemplateVariableContainer($variableContainer);
216 if ($parsedTemplate->isCompiled()) {
217 $methodNameOfSection =
'section_' . sha1($sectionName);
218 if ($ignoreUnknown && !method_exists($parsedTemplate, $methodNameOfSection)) {
221 $this->
startRendering($renderingTypeOnNextLevel, $parsedTemplate, $renderingContext);
222 $output = $parsedTemplate->{$methodNameOfSection}($renderingContext);
225 $sections = $parsedTemplate->getVariableContainer()->get(
'sections');
226 if (!array_key_exists($sectionName, $sections)) {
227 $controllerObjectName = $this->controllerContext->getRequest()->getControllerObjectName();
228 if ($ignoreUnknown) {
231 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);
234 $section = $sections[$sectionName];
236 $renderingContext->getViewHelperVariableContainer()->add(
'TYPO3\\CMS\\Fluid\\ViewHelpers\\SectionViewHelper',
'isCurrentlyRenderingSection',
'TRUE');
238 $this->
startRendering($renderingTypeOnNextLevel, $parsedTemplate, $renderingContext);
239 $output = $section->evaluate($renderingContext);
255 public function renderPartial($partialName, $sectionName, array $variables) {
256 $partialNameWithFormat = $partialName .
'.' . $this->controllerContext->getRequest()->getFormat();
257 if (!isset($this->partialIdentifierCache[$partialNameWithFormat])) {
258 $this->partialIdentifierCache[$partialNameWithFormat] = $this->
getPartialIdentifier($partialName);
260 $partialIdentifier = $this->partialIdentifierCache[$partialNameWithFormat];
262 if ($this->templateCompiler->has($partialIdentifier)) {
263 $parsedPartial = $this->templateCompiler->get($partialIdentifier);
265 $parsedPartial = $this->templateParser->parse($this->
getPartialSource($partialName));
266 if ($parsedPartial->isCompilable()) {
267 $this->templateCompiler->store($partialIdentifier, $parsedPartial);
271 $variableContainer = $this->objectManager->get(
'TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TemplateVariableContainer', $variables);
273 $renderingContext->injectTemplateVariableContainer($variableContainer);
275 $this->
startRendering(self::RENDERING_PARTIAL, $parsedPartial, $renderingContext);
276 if ($sectionName !== NULL) {
279 $output = $parsedPartial->render($renderingContext);
352 $parserConfiguration = $this->objectManager->get(
'TYPO3\\CMS\\Fluid\\Core\\Parser\\Configuration');
353 if ($this->controllerContext->getRequest()->getFormat() ===
'html') {
354 $parserConfiguration->addInterceptor($this->objectManager->get(
'TYPO3\\CMS\\Fluid\\Core\\Parser\\Interceptor\\Escape'));
356 return $parserConfiguration;
367 protected function startRendering($type, \
TYPO3\CMS\
Fluid\Core\Parser\ParsedTemplateInterface $parsedTemplate, \
TYPO3\CMS\
Fluid\Core\Rendering\RenderingContextInterface $renderingContext) {
368 array_push($this->renderingStack, array(
'type' => $type,
'parsedTemplate' => $parsedTemplate,
'renderingContext' => $renderingContext));
378 array_pop($this->renderingStack);
387 $currentRendering = end($this->renderingStack);
388 return $currentRendering[
'type'];
397 $currentRendering = end($this->renderingStack);
398 return $currentRendering[
'parsedTemplate'];
407 $currentRendering = end($this->renderingStack);
408 return $currentRendering[
'renderingContext'];
canRender(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext)
getLayoutSource($layoutName='Default')
getCurrentRenderingType()
getPartialSource($partialName)
getTemplateIdentifier($actionName=NULL)
setRenderingContext(\TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
static makeInstance($className)
renderPartial($partialName, $sectionName, array $variables)
buildParserConfiguration()
assignMultiple(array $values)
getLayoutIdentifier($layoutName='Default')
getPartialIdentifier($partialName)
getCurrentRenderingContext()
getCurrentParsedTemplate()
setControllerContext(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext)
injectTemplateCompiler(\TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler $templateCompiler)
getTemplateSource($actionName=NULL)
startRendering($type, \TYPO3\CMS\Fluid\Core\Parser\ParsedTemplateInterface $parsedTemplate, \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
renderSection($sectionName, array $variables, $ignoreUnknown=FALSE)