Browse Source

Fix {#ignore}{/ignore}

Nathaniel van Diepen 7 years ago
parent
commit
071a4fc496
1 changed files with 5 additions and 3 deletions
  1. 5 3
      Data/template.class.php

+ 5 - 3
Data/template.class.php

@@ -56,9 +56,9 @@
 		public static function parse(string $template, $data){
 			$ignored = [];
 			// Handle {#ignore code}
-			$output = preg_replace_callback(static::$regex['ignore'], function($matches) use($ignored){
+			$output = preg_replace_callback(static::$regex['ignore'], function($matches) use(&$ignored){
 				$ignored[] = $matches[1];
-				return '{#ignored '.count($ignored).'}';
+				return '{#ignored '.(count($ignored) - 1).'}';
 			}, $template);
 			// Handle {#each name}{/each}
 			$output = preg_replace_callback(static::$regex['each'], function($matches) use($data){
@@ -101,7 +101,9 @@
 			$output = preg_replace_callback(static::$regex['match'], function($matches) use($data){
 				return $data[$matches[1]] ?? '';
 			}, $output);
-			return $output;
+			return preg_replace_callback(static::$regex['ignored'], function($matches) use(&$ignored){
+				return $ignored[(int)$matches[1]] ?? '';
+			}, $output);
 		}
 	}
 ?>