From 509084aabace92711efa453bd74c7ca24eabeb37 Mon Sep 17 00:00:00 2001 From: sam159 Date: Mon, 2 Jun 2014 22:14:27 +0100 Subject: [PATCH] Fixed issue with rendering a template within a section --- Template.php | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/Template.php b/Template.php index b57d254..3d68fef 100644 --- a/Template.php +++ b/Template.php @@ -39,9 +39,9 @@ class Template private $sections = array(); private $currentSection = false; - private $master = false; private function __construct() { + $this->context[0]['master'] = false; } private function GetCompiledFilename($tFile) { @@ -74,7 +74,7 @@ class Template public function Render($file, array $context = array()) { self::$currentTemplater = $this; - + $tFile = str_replace('.', DS, $file); $tFile = DIR_TEMPLATES.DS.$tFile.'.php'; if (!is_file($tFile)) @@ -86,9 +86,7 @@ class Template $this->context[$this->level] = &$context; extract($this->context[$this->level], EXTR_REFS | EXTR_SKIP); - - $this->master = false; - + $compiledTemplate = $this->GetCompiled($tFile); if ($compiledTemplate == false) { $templateContents = file_get_contents($tFile); @@ -97,19 +95,21 @@ class Template array('$1 ;?>', '', '$1 ;?>', ''), $templateContents); $this->SaveCompiled($tFile, $templateContents); - $result = eval('?>'.$templateContents); + ob_start(); + eval('?>'.$templateContents); + $result = ob_get_contents(); + ob_end_clean(); } else { ob_start(); include($compiledTemplate); - $result = ob_get_clean(); + $result = ob_get_contents(); + ob_end_clean(); } self::$currentTemplater = false; - if ($this->currentSection != False) - $this->EndSection(); - if ($this->master != false) { - return $this->Render($this->master); + if ($this->context[0]['master'] != false && $this->level == 1) { + return $this->Render($this->context[0]['master']); } unset($this->context[$this->level]); @@ -119,14 +119,15 @@ class Template } private function SetMaster($file) { - $this->master = $file; + $this->context[0]['master'] = $file; } private function StartSection($name) { $this->currentSection = $name; ob_start(); } private function EndSection() { - $this->sections[$this->currentSection] = ob_get_clean(); + $this->sections[$this->currentSection] = ob_get_contents(); + ob_end_clean(); $this->currentSection = false; } private function GetSection($name) {