FluidTYPO3\Vhs\ViewHelpers\Variable\SetViewHelper::render PHP Method

render() public method

Set (override) the variable in $name.
public render ( string $name, mixed $value = null ) : void
$name string
$value mixed
return void
    public function render($name, $value = null)
    {
        if (null === $value) {
            $value = $this->renderChildren();
        }
        if (false === strpos($name, '.')) {
            if (true === $this->templateVariableContainer->exists($name)) {
                $this->templateVariableContainer->remove($name);
            }
            $this->templateVariableContainer->add($name, $value);
        } elseif (1 === substr_count($name, '.')) {
            $parts = explode('.', $name);
            $objectName = array_shift($parts);
            $path = implode('.', $parts);
            if (false === $this->templateVariableContainer->exists($objectName)) {
                return null;
            }
            $object = $this->templateVariableContainer->get($objectName);
            try {
                ObjectAccess::setProperty($object, $path, $value);
                // Note: re-insert the variable to ensure unreferenced values like arrays also get updated
                $this->templateVariableContainer->remove($objectName);
                $this->templateVariableContainer->add($objectName, $object);
            } catch (\Exception $error) {
                return null;
            }
        }
        return null;
    }
SetViewHelper