/** * Evaluate the TypoScript object at $path and return the rendered result. * * @param string $path Relative TypoScript path to be rendered * @param array $context Additional context variables to be set. * @param string $typoScriptPackageKey The key of the package to load TypoScript from, if not from the current context. * @return string * @throws \InvalidArgumentException */ public function render($path, array $context = null, $typoScriptPackageKey = null) { if (strpos($path, '/') === 0 || strpos($path, '.') === 0) { throw new \InvalidArgumentException('When calling the TypoScript render view helper only relative paths are allowed.', 1368740480); } if (preg_match('/^[a-z0-9.]+$/i', $path) !== 1) { throw new \InvalidArgumentException('Invalid path given to the TypoScript render view helper ', 1368740484); } $slashSeparatedPath = str_replace('.', '/', $path); if ($typoScriptPackageKey === null) { /** @var $typoScriptObject AbstractTypoScriptObject */ $typoScriptObject = $this->viewHelperVariableContainer->getView()->getTypoScriptObject(); if ($context !== null) { $currentContext = $typoScriptObject->getTsRuntime()->getCurrentContext(); foreach ($context as $key => $value) { $currentContext[$key] = $value; } $typoScriptObject->getTsRuntime()->pushContextArray($currentContext); } $absolutePath = $typoScriptObject->getPath() . '/' . $slashSeparatedPath; $output = $typoScriptObject->getTsRuntime()->render($absolutePath); if ($context !== null) { $typoScriptObject->getTsRuntime()->popContext(); } } else { $this->initializeTypoScriptView(); $this->typoScriptView->setPackageKey($typoScriptPackageKey); $this->typoScriptView->setTypoScriptPath($slashSeparatedPath); if ($context !== null) { $this->typoScriptView->assignMultiple($context); } $output = $this->typoScriptView->render(); } return $output; }
/** * Helper to build a TypoScript view object * * @return TypoScriptView */ protected function buildView() { $view = new TypoScriptView(); $httpRequest = Request::createFromEnvironment(); $request = $httpRequest->createActionRequest(); $uriBuilder = new UriBuilder(); $uriBuilder->setRequest($request); $this->controllerContext = new ControllerContext($request, new Response(), new Arguments(array()), $uriBuilder); $view->setControllerContext($this->controllerContext); $view->disableFallbackView(); $view->setPackageKey('TYPO3.TypoScript'); $view->setTypoScriptPathPattern(__DIR__ . '/Fixtures/TypoScript'); $view->assign('fixtureDirectory', __DIR__ . '/Fixtures/'); return $view; }