/** * Render content inside layout * * @param Content $content Content object * @return string */ public function render(Content $content, $vars = array()) { $layout = $this->getLayout(); if ($content->getName() != 'index') { if ($item = $this->getActiveNavigationItem()) { $layout->setTitle($item->getText()); } if ($subItem = $this->getActiveSubNavigationItem()) { $layout->setTitle($subItem->getText()); } } $layout->setTitle($content->getTitle()); // Fetch all the metadata from the content and set it to the layout so // it can be accessed by the layout view template. foreach ($content->getMetadata() as $name => $value) { $layout->setParam($name, $value); } return $layout->render($content->render(), $vars); }
/** * Handle thrown exceptions * * @param \Exception $exception The Exception object * @return void */ public static function handleException(\Exception $exception) { $request = new Request(); try { $theme = new Theme(self::getKernel()->getConfig('theme'), $request->getBaseUrl()); $view = new View($theme); $view->setParams(self::getKernel()->getConfig()); if ($exception instanceof \Greengrape\Exception\NotFoundException) { $httpHeader = 'HTTP/1.1 404 Not Found'; $templateFile = '404.html'; } else { $httpHeader = 'HTTP/1.1 500 Internal Server Error'; $templateFile = 'error.html'; } if (!headers_sent()) { header($httpHeader); } $content = new Content('', $view); $content->setTemplateFile($templateFile); $content->setContent($exception->getMessage() . '<pre>' . $exception->getTraceAsString() . '</pre>'); $vars = array('trace' => self::displayException($exception)); echo $view->render($content, $vars); } catch (\Exception $newException) { $errorTitle = 'Exception found while handling exception:'; $message = htmlentities($newException->getMessage()); printf(self::EXCEPTION_MESSAGE_CAPSULE, $errorTitle, $message); print self::displayException($newException); if ($newException->getMessage() != $exception->getMessage()) { $errorTitle = 'This was the original exception:'; $message = htmlentities($exception->getMessage()); printf(self::EXCEPTION_MESSAGE_CAPSULE, $errorTitle, $message); } } }
/** * testGetThemeWhenNotSet * * @expectedException Greengrape\Exception\GreengrapeException * @return void */ public function testGetThemeWhenNotSet() { $content = new Content('mycontentfile.md'); $theme = $content->getTheme(); }