From: Robert Sesek Date: Mon, 8 Aug 2011 02:19:03 +0000 (-0400) Subject: Add functionality to OutputFilter for rendering templates X-Git-Tag: api-2~41 X-Git-Url: https://src.bluestatic.org/?a=commitdiff_plain;h=42e8595bb55a2d447069bb39ccddacaae15a1355;p=hoplite.git Add functionality to OutputFilter for rendering templates --- diff --git a/http/output_filter.php b/http/output_filter.php index 79031ce..5f702ac 100644 --- a/http/output_filter.php +++ b/http/output_filter.php @@ -17,6 +17,7 @@ namespace hoplite\http; require_once HOPLITE_ROOT . '/http/response_code.php'; +require_once HOPLITE_ROOT . '/views/template_loader.php'; /*! The OutputFilter is executed after all Actions have been processed. The @@ -34,6 +35,11 @@ class OutputFilter */ const RESPONSE_TYPE = 'response_type'; + /*! @const A key in Response#context to render a template with the + Response#data when creating a HTML body. + */ + const RENDER_TEMPLATE = 'template'; + /*! Constructor that takes a reference to the RootController. */ @@ -123,6 +129,10 @@ class OutputFilter $response->body = $this->_EncodeXML($response->data); } else if ($type == 'html') { $response->headers['Content-Type'] = 'text/html'; + if (isset($response->context[self::RENDER_TEMPLATE])) { + $template = \hoplite\views\TemplateLoader::Fetch($response->context[self::RENDER_TEMPLATE]); + $response->body = $template->Render($response->data); + } } }