src/Renderer/TwigRenderer.php
public function render($nameOrModel, $values = null) : string
    {
        $model = $nameOrModel;
        if ($model instanceof ModelInterface) {
            $nameOrModel = $model->getTemplate();

            if (empty($nameOrModel)) {
                throw new DomainException(sprintf(
                    '%s: received View Model argument, but template is empty',
                    __METHOD__
                ));
            }

            $options = $model->getOptions();
            $options = empty($options) ? [] : $options;
            foreach ($options as $setting => $value) {
                $method = 'set' . $setting;
                if (method_exists($this, $method)) {
                    $this->$method($value);
                }
                unset($method, $setting, $value);
            }

            /**
             * Give view model awareness via ViewModel helper
             * @var \Zend\View\Helper\ViewModel $helper
             */
            $helper = $this->plugin(ViewModel::class);
            $helper->setCurrent($model);

            $values = $model->getVariables();
        }

        if (!$this->canRender($nameOrModel)) {
            throw new RuntimeException(sprintf(
                '%s: Unable to render template "%s"; resolver could not resolve to a file',
                __METHOD__,
                $nameOrModel
            ));
        }

        if ($model instanceof ModelInterface && $model->hasChildren() && $this->canRenderTrees()) {
            if (!isset($values[$model->captureTo()])) {
                $values[$model->captureTo()] = '';
            }

            foreach ($model->getChildren() as $child) {
                /**
                 * @var \Zend\View\Model\ViewModel $child
                 * @var \Twig_Template             $template
                 */
                $result = $this->render($child, $values);

                if ($this->isForceStandalone() || $child->terminate()) {
                    return $result;
                }

                $child->setOption('has_parent', true);

                if ($child->isAppend()) {
                    $values[$child->captureTo()] .= $result;
                } else {
                    $values[$child->captureTo()] = $result;
                }
            }
        }

        /** @var \Twig_Template $template */
        $template = $this->getResolver()->resolve($nameOrModel, $this);

        return $template->render((array)$values);
    }
public function render($nameOrModel, $values = null) : string
    {
        $model = $nameOrModel;
        if ($model instanceof ModelInterface) {
            $nameOrModel = $model->getTemplate();

            if (empty($nameOrModel)) {
                throw new DomainException(sprintf(
                    '%s: received View Model argument, but template is empty',
                    __METHOD__
                ));
            }

            $options = $model->getOptions();
            $options = empty($options) ? [] : $options;
            foreach ($options as $setting => $value) {
                $method = 'set' . $setting;
                if (method_exists($this, $method)) {
                    $this->$method($value);
                }
                unset($method, $setting, $value);
            }

            /**
             * Give view model awareness via ViewModel helper
             * @var \Zend\View\Helper\ViewModel $helper
             */
            $helper = $this->plugin(ViewModel::class);
            $helper->setCurrent($model);

            $values = $model->getVariables();
        }

        if (!$this->canRender($nameOrModel)) {
            throw new RuntimeException(sprintf(
                '%s: Unable to render template "%s"; resolver could not resolve to a file',
                __METHOD__,
                $nameOrModel
            ));
        }

        if ($model instanceof ModelInterface && $model->hasChildren() && $this->canRenderTrees()) {
            if (!isset($values[$model->captureTo()])) {
                $values[$model->captureTo()] = '';
            }

            foreach ($model->getChildren() as $child) {
                /**
                 * @var \Zend\View\Model\ViewModel $child
                 * @var \Twig_Template             $template
                 */
                $result = $this->render($child, $values);

                if ($this->isForceStandalone() || $child->terminate()) {
                    return $result;
                }

                $child->setOption('has_parent', true);

                if ($child->isAppend()) {
                    $values[$child->captureTo()] .= $result;
                } else {
                    $values[$child->captureTo()] = $result;
                }
            }
        }

        /** @var \Twig_Template $template */
        $template = $this->getResolver()->resolve($nameOrModel, $this);

        return $template->render((array)$values);
    }
Processes a view script and returns the output.

@param  string|ModelInterface   $nameOrModel The script/resource process, or a view model
@param  null|array|\ArrayAccess $values      Values to use during rendering

@return string The script output.