From 42e8595bb55a2d447069bb39ccddacaae15a1355 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 7 Aug 2011 22:19:03 -0400 Subject: [PATCH] Add functionality to OutputFilter for rendering templates --- http/output_filter.php | 10 ++++++++++ 1 file changed, 10 insertions(+) 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); + } } } -- 2.43.5