/** * 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. * @throws \LogicException */ public function render($nameOrModel, $values = null) { $name = $nameOrModel; if ($nameOrModel instanceof ModelInterface) { $name = $this->resolver->resolve($nameOrModel->getTemplate(), $this); $values = (array) $nameOrModel->getVariables(); } if (array_key_exists('helper', $values)) { throw new \LogicException('Variable $helper is reserved for Zend helpers and can\'t be passed to view.'); } $values['helper'] = $this->helpers; return $this->engine->renderToString($name, $values); }
/** * Recursively search a view model and it's children for the given templateName * * @param \Zend\View\Model\ModelInterface $viewModel * @param string $templateName * @return boolean */ protected function searchTemplates($viewModel, $templateName) { if ($viewModel->getTemplate($templateName) == $templateName) { return true; } foreach ($viewModel->getChildren() as $child) { return $this->searchTemplates($child, $templateName); } return false; }
/** * assign wrapper template to block * * @param ModelInterface $block * @param array|string $options */ protected function wrapBlock(ModelInterface $block, $options) { $attributes = $options; if (is_string($options)) { $wrapperTemplate = $options; $attributes = []; } elseif (is_array($options) && !isset($options['template'])) { $wrapperTemplate = self::WRAPPER_DEFAULT; } else { $wrapperTemplate = $options['template']; unset($attributes['template']); } if (isset($options['tag'])) { $block->setVariable('wrapperTag', $options['tag']); unset($attributes['tag']); } $originalTemplate = $block->getTemplate(); $block->setOption('is_wrapped', true); $block->setTemplate($wrapperTemplate); $block->setVariable('wrapperAttributes', $attributes); $block->setVariable('originalTemplate', $originalTemplate); }