final public function render($content = null) {
        if ($content === null) {
            foreach ($this->view->getVariables() as $var => $val) {
                $$var = $val;
            }

            $viewFile = $this->view->getViewFile();
            if (!is_readable(MODULES . $viewFile[0] . DIRECTORY_SEPARATOR . 'View' .
                            DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR .
                            $viewFile[1] . DIRECTORY_SEPARATOR . $viewFile[2] . '.phtml'))
                throw new Exception('View layout "' . join(DIRECTORY_SEPARATOR, $viewFile) . '" not found');

            // include action view
            ob_start();

            include_once MODULES . $viewFile[0] . DIRECTORY_SEPARATOR . 'View' .
                    DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR .
                    $viewFile[1] . DIRECTORY_SEPARATOR . $viewFile[2] . '.phtml';

            $content = ob_get_clean();
            if (!$this->view->isPartial()) {
                // include controller layout
                $controllerLayout = self::getLayoutPath();
                if ($controllerLayout) {
                    ob_start();
                    include_once $controllerLayout;

                    $content = ob_get_clean();
                }
                else if (engineGet('config', 'defaults', 'defaultLayout', false)) {
                    ob_start();
                    $this->loadLayout(engineGet('config', 'defaults', 'defaultLayout'), array('content' => $content));
                    $content = ob_get_clean();
                }
                else {
                    throw new Exception('No layout found.');
                }
            }
        }
        else {
            if (!$errorLayout = engineGet('config', 'modules', $this->view->getModule(), 'defaults', 'errorLayout', false)) {
                if (!$errorLayout = engineGet('config', 'defaults', 'errorLayout', false)) {
                    throw new Exception('Error layout not found', true);
                }
            }

            if (is_array($errorLayout)) {
                if (!array_key_exists('guest', $errorLayout))
                    throw new Exception('Error layout not found for "guest"', true);

                if (array_key_exists($this->userIdentity()->getUser()->getRole(), $errorLayout))
                    $errorLayout = $errorLayout[$this->userIdentity()->getUser()->getRole()];
                else
                    $errorLayout = $errorLayout['guest'];
            }

            ob_start();
            $this->loadLayout($errorLayout, array_merge(array('content' => $content), $this->view->getVariables()));
            $content = ob_get_clean();
        }
        echo($content);
    }