Neos\Fusion\ViewHelpers\RenderViewHelper::render PHP Method

render() public method

Evaluate the Fusion object at $path and return the rendered result.
public render ( string $path, array $context = null, string $typoScriptPackageKey = null ) : string
$path string Relative Fusion path to be rendered
$context array Additional context variables to be set.
$typoScriptPackageKey string The key of the package to load Fusion from, if not from the current context.
return string
    public function render($path, array $context = null, $typoScriptPackageKey = null)
    {
        if (strpos($path, '/') === 0 || strpos($path, '.') === 0) {
            throw new \InvalidArgumentException('When calling the Fusion 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 Fusion 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->initializeFusionView();
            $this->typoScriptView->setPackageKey($typoScriptPackageKey);
            $this->typoScriptView->setTypoScriptPath($slashSeparatedPath);
            if ($context !== null) {
                $this->typoScriptView->assignMultiple($context);
            }
            $output = $this->typoScriptView->render();
        }
        return $output;
    }