From 598a60b09bbc19bb3afb7819fbe23ab0c612b4c7 Mon Sep 17 00:00:00 2001 From: Evan Purkhiser Date: Fri, 15 Mar 2013 19:24:02 -0400 Subject: [PATCH] Kostache_Layout: Load content as mustache source This fixes issues caused by the content partial being rendered and then injected as a partial in the layout template and being rendered again --- classes/Kohana/Kostache.php | 13 ++++++++++--- classes/Kohana/Kostache/Layout.php | 12 +++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/classes/Kohana/Kostache.php b/classes/Kohana/Kostache.php index 6f53a9b..89f53f8 100644 --- a/classes/Kohana/Kostache.php +++ b/classes/Kohana/Kostache.php @@ -40,11 +40,18 @@ public function render($class, $template = NULL) { if ($template == NULL) { - $template = explode('_', get_class($class)); - array_shift($template); - $template = implode('/', $template); + $template = $this->_detect_template_path($class); } return $this->_engine->loadTemplate($template)->render($class); } + + protected function _detect_template_path($class) + { + $path = explode('_', get_class($class)); + array_shift($path); + + return implode('/', $path); + } + } diff --git a/classes/Kohana/Kostache/Layout.php b/classes/Kohana/Kostache/Layout.php index 1f85dc1..7627a6b 100644 --- a/classes/Kohana/Kostache/Layout.php +++ b/classes/Kohana/Kostache/Layout.php @@ -34,11 +34,13 @@ public function set_layout($layout) public function render($class, $template = NULL) { - $this->_engine->setPartials( - array( - Kostache_Layout::CONTENT_PARTIAL => parent::render($class, $template) - ) - ); + $content = $this->_engine + ->getLoader() + ->load($this->_detect_template_path($class)); + + $this->_engine->setPartials(array( + Kostache_Layout::CONTENT_PARTIAL => $content + )); return $this->_engine->loadTemplate($this->_layout)->render($class); }