From cc1a11a21534cc152e0e99b23ad66ad7ad345e60 Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Tue, 17 Sep 2013 22:15:55 +0300 Subject: [PATCH] fix block nesting --- lib/compiler.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/compiler.php b/lib/compiler.php index bc16450..654e7e7 100644 --- a/lib/compiler.php +++ b/lib/compiler.php @@ -87,6 +87,7 @@ class IPF_Template_Compiler if ($count == 0) { $result[] = array( 'name' => $tag[1][0], + 'block_start' => $tag[0][1], 'start' => $tag[1][1] + strlen($tag[1][0]) + 1, ); } @@ -94,6 +95,7 @@ class IPF_Template_Compiler } elseif (substr($text, 0, 7) === '{/block') { $count--; if ($count == 0) { + $result[count($result)-1]['block_finish'] = $tag[0][1] + strlen($text); $result[count($result)-1]['finish'] = $tag[0][1]; } } @@ -137,9 +139,18 @@ class IPF_Template_Compiler $this->compileBlocks(); //It will recurse to the base template. } else { // Replace the current blocks by a place holder - if ($cnt) { - $this->templateContent = preg_replace("!{block\s(\S+?)}(.*?){/block}!s", "{block $1}", $tplcontent, -1); + $start = 0; + $content = ''; + foreach ($blocks as $block) { + $content .= substr($this->templateContent, $start, $block['block_start'] - $start); + $start = $block['block_finish']; + + $blockName = $block['name']; + $content .= "{block $blockName}"; } + $content .= substr($this->templateContent, $start); + + $this->templateContent = $content; } } -- 2.49.0