/**
  * Check if $value is valid. If it is not valid, needs to add an error
  * to Result.
  *
  * @param mixed $value
  * @return void
  */
 protected function isValid($value)
 {
     try {
         $this->parser->parse($value);
     } catch (\Exception $e) {
         $this->addError("Could not parse fluid template: " . $e->getMessage(), 1418149684);
     }
 }
 /**
  * Renders a partial.
  *
  * @param string $partialName
  * @param string $sectionName
  * @param array $variables
  * @param \TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperVariableContainer $viewHelperVariableContainer the View Helper Variable container to use.
  * @return string
  */
 public function renderPartial($partialName, $sectionName, array $variables)
 {
     $partialNameWithFormat = $partialName . '.' . $this->controllerContext->getRequest()->getFormat();
     if (!isset($this->partialIdentifierCache[$partialNameWithFormat])) {
         $this->partialIdentifierCache[$partialNameWithFormat] = $this->getPartialIdentifier($partialName);
     }
     $partialIdentifier = $this->partialIdentifierCache[$partialNameWithFormat];
     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);
         }
     }
     $variableContainer = $this->objectManager->get('TYPO3\\CMS\\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;
 }
Esempio n. 3
0
 /**
  * Syntax checks a Fluid template file by attempting
  * to load the file and retrieve a parsed template, which
  * will cause traversal of the entire syntax node tree
  * and report any errors about missing or unknown arguments.
  *
  * Will NOT, however, report errors which are caused by
  * variables assigned to the template (there will be no
  * variables while building the syntax tree and listening
  * for errors).
  *
  * @param string $filePathAndFilename
  * @return FluidParserResult
  * @throws \Exception
  */
 public function syntaxCheckFluidTemplateFile($filePathAndFilename)
 {
     /** @var FluidParserResult $result */
     $result = $this->objectManager->get('FluidTYPO3\\Builder\\Result\\FluidParserResult');
     /** @var RenderingContext $context */
     $context = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\Rendering\\RenderingContext');
     try {
         $parsedTemplate = $this->templateParser->parse(file_get_contents($filePathAndFilename));
         $result->setLayoutName($parsedTemplate->getLayoutName($context));
         $result->setNamespaces($this->templateParser->getNamespaces());
         $result->setCompilable($parsedTemplate->isCompilable());
     } catch (\Exception $error) {
         $result->setError($error);
         $result->setValid(FALSE);
     }
     return $result;
 }
Esempio n. 4
0
 public function parse($templateString)
 {
     if (substr($templateString, 0, 7) === 'smarty:') {
         $templateString = substr($templateString, 7);
         $state = $this->objectManager->get(\TYPO3\CMS\Fluid\Core\Parser\ParsingState::class);
         $rootNode = $this->objectManager->get(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode::class);
         $state->setRootNode($rootNode);
         $state->pushNodeToStack($rootNode);
         $viewHelper = $this->objectManager->get(\Vierwd\VierwdSmarty\ViewHelper\SmartyViewHelper::class);
         $node = $this->objectManager->get(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode::class, $viewHelper, []);
         $state->getNodeFromStack()->addChildNode($node);
         $textNode = $this->objectManager->get(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode::class, $templateString);
         $node->addChildNode($textNode);
         return $state;
     }
     return parent::parse($templateString);
 }
 /**
  * @test
  * @expectedException \TYPO3\CMS\Fluid\Core\Parser\Exception
  */
 public function parseThrowsExceptionWhenStringArgumentMissing()
 {
     $templateParser = new \TYPO3\CMS\Fluid\Core\Parser\TemplateParser();
     $templateParser->parse(123);
 }