public function render($template = null, $vars = null)
    {
        $context = $this->_context;

        if ($vars !== null) {
            $context->vars = $vars;
        }

        if (!$template) {
            $area = $this->dispatcher->getArea();
            $controller = $this->dispatcher->getController();

            if ($area) {
                $dir = "@app/Areas/$area/Views/$controller";
            } else {
                $dir = "@views/$controller";
            }

            if (!isset($this->_dirs[$dir])) {
                $this->_dirs[$dir] = $this->filesystem->dirExists($dir);
            }

            if ($this->_dirs[$dir]) {
                $template = $dir . '/' . ucfirst($this->dispatcher->getAction());
            } else {
                $template = $dir;
            }
        }

        $this->eventsManager->fireEvent('view:beforeRender', $this);

        $context->content = $this->_render($template, $context->vars, false);

        if ($context->layout !== false) {
            $layout = $this->_findLayout();
            $context->content = $this->_render($layout, $context->vars, false);
        }

        $this->eventsManager->fireEvent('view:afterRender', $this);

        return $context->content;
    }