]> git.andy128k.dev Git - ipf-template.git/commitdiff
fix block nesting
authorAndrey Kutejko <andy128k@gmail.com>
Tue, 17 Sep 2013 19:15:55 +0000 (22:15 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Tue, 17 Sep 2013 19:15:55 +0000 (22:15 +0300)
lib/compiler.php

index bc164503f9159282dfded00b3c1d17b95ea08b72..654e7e7a3bb12ce86ac141dcbe27b372b547065e 100644 (file)
@@ -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;
         }
     }