/** * Render the cell. * * @param string|null $template Custom template name to render. If not provided (null), the last * value will be used. This value is automatically set by `CellTrait::cell()`. * @return string The rendered cell. * @throws \Cake\View\Exception\MissingCellViewException When a MissingTemplateException is raised during rendering. */ public function render($template = null) { if ($template !== null && strpos($template, '/') === false && strpos($template, '.') === false) { $template = Inflector::underscore($template); } if ($template === null) { $template = $this->template; } $builder = $this->viewBuilder(); $builder->layout(false); $builder->template($template); $cache = []; if ($this->_cache) { $cache = $this->_cacheConfig($template); } $this->View = $this->createView(); $render = function () use($template) { $className = substr(strrchr(get_class($this), "\\"), 1); $name = substr($className, 0, -4); $this->View->templatePath('Cell' . DS . $name); try { return $this->View->render($template); } catch (MissingTemplateException $e) { throw new MissingCellViewException(['file' => $template, 'name' => $name]); } }; if ($cache) { return $this->View->cache(function () use($render) { echo $render(); }, $cache); } return $render(); }