/**
  * 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 {
         $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', $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;
 }
Exemplo 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 $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;
 }
 /**
  * The compiled ViewHelper adds two new ViewHelper arguments: __thenClosure and __elseClosure.
  * These contain closures which are be executed to render the then(), respectively else() case.
  *
  * @param string $argumentsVariableName
  * @param string $renderChildrenClosureVariableName
  * @param string $initializationPhpCode
  * @param AbstractNode $syntaxTreeNode
  * @param TemplateCompiler $templateCompiler
  * @return string
  * @Flow\Internal
  */
 public function compile($argumentsVariableName, $renderChildrenClosureVariableName, &$initializationPhpCode, AbstractNode $syntaxTreeNode, TemplateCompiler $templateCompiler)
 {
     foreach ($syntaxTreeNode->getChildNodes() as $childNode) {
         if ($childNode instanceof ViewHelperNode && $childNode->getViewHelperClassName() === \TYPO3\Fluid\ViewHelpers\ThenViewHelper::class) {
             $childNodesAsClosure = $templateCompiler->wrapChildNodesInClosure($childNode);
             $initializationPhpCode .= sprintf('%s[\'__thenClosure\'] = %s;', $argumentsVariableName, $childNodesAsClosure) . chr(10);
         }
         if ($childNode instanceof ViewHelperNode && $childNode->getViewHelperClassName() === \TYPO3\Fluid\ViewHelpers\ElseViewHelper::class) {
             $childNodesAsClosure = $templateCompiler->wrapChildNodesInClosure($childNode);
             $initializationPhpCode .= sprintf('%s[\'__elseClosure\'] = %s;', $argumentsVariableName, $childNodesAsClosure) . chr(10);
         }
     }
     return TemplateCompiler::SHOULD_GENERATE_VIEWHELPER_INVOCATION;
 }
 /**
  * @param string $argumentsVariableName
  * @param string $renderChildrenClosureVariableName
  * @param string $initializationPhpCode
  * @param \TYPO3\Fluid\Core\Parser\SyntaxTree\AbstractNode $syntaxTreeNode
  * @param \TYPO3\Fluid\Core\Compiler\TemplateCompiler $templateCompiler
  * @return string
  */
 public function compile($argumentsVariableName, $renderChildrenClosureVariableName, &$initializationPhpCode, \TYPO3\Fluid\Core\Parser\SyntaxTree\AbstractNode $syntaxTreeNode, \TYPO3\Fluid\Core\Compiler\TemplateCompiler $templateCompiler)
 {
     $valueVariableName = $templateCompiler->variableName('value');
     $initializationPhpCode .= sprintf('%s = (%s[\'value\'] !== NULL ? %s[\'value\'] : %s());', $valueVariableName, $argumentsVariableName, $argumentsVariableName, $renderChildrenClosureVariableName) . chr(10);
     return sprintf('(!is_string(%s) ? %s : htmlspecialchars(%s, (%s[\'keepQuotes\'] ? ENT_NOQUOTES : ENT_COMPAT), %s[\'encoding\'], %s[\'doubleEncode\']))', $valueVariableName, $valueVariableName, $valueVariableName, $argumentsVariableName, $argumentsVariableName, $argumentsVariableName);
 }
 /**
  * This ViewHelper is used a *lot* because it is used by the escape interceptor.
  * Therefore we render it to raw PHP code during compilation
  *
  * @param string $argumentsVariableName
  * @param string $renderChildrenClosureVariableName
  * @param string $initializationPhpCode
  * @param AbstractNode $syntaxTreeNode
  * @param TemplateCompiler $templateCompiler
  * @return string
  */
 public function compile($argumentsVariableName, $renderChildrenClosureVariableName, &$initializationPhpCode, AbstractNode $syntaxTreeNode, TemplateCompiler $templateCompiler)
 {
     $valueVariableName = $templateCompiler->variableName('value');
     $initializationPhpCode .= sprintf('%1$s = (%2$s[\'value\'] !== NULL ? %2$s[\'value\'] : %3$s());', $valueVariableName, $argumentsVariableName, $renderChildrenClosureVariableName) . chr(10);
     return sprintf('!is_string(%1$s) && !(is_object(%1$s) && method_exists(%1$s, \'__toString\')) ? %1$s : htmlspecialchars(%1$s, (%2$s[\'keepQuotes\'] ? ENT_NOQUOTES : ENT_COMPAT), %2$s[\'encoding\'], %2$s[\'doubleEncode\'])', $valueVariableName, $argumentsVariableName);
 }
Exemplo n.º 6
0
 /**
  * @return string
  */
 public function getTemplateCacheDir()
 {
     return $this->templateCompiler->getTemplateCacheDir();
 }