Browse Source

* Fix bug with exist/each/existelse/match
* Add base data to views

Nathaniel van Diepen 7 years ago
parent
commit
b52eca8fb9
2 changed files with 10 additions and 4 deletions
  1. 6 0
      App/view.abstract.class.php
  2. 4 4
      Data/template.class.php

+ 6 - 0
App/view.abstract.class.php

@@ -19,11 +19,17 @@
 			}
 			return static::$name;
 		}
+		public static function data(){
+			return [
+				'view'=>get_called_class()
+			];
+		}
 		final public static function render(array $data = []) : string{
 			if(is_null(static::$template) && method_exists(get_called_class(), 'setup')){
 				static::setup();
 			}
 			$template = static::$template ?? static::name();
+			$data = array_merge(static::data(),$data);
 			if(is_string($template)){
 				return Template::from($template, $data);
 			}elseif(is_array($template)){

+ 4 - 4
Data/template.class.php

@@ -11,10 +11,10 @@
 		public static $cachedir;
 		public static $basedir = __DIR__;
 		private static $regex = [
-			'match'=>'/\{([^#\/][^}\n]+?)\}/i',
-			'each'=>'/\{#each ([^}]*)\}([\S\s]*)\{\/each\}/i',
-			'exist'=>'/\{#exist ([^}]*)\}([\S\s]*)\{\/exist\}/i',
-			'existelse'=>'/\{#exist ([^}]*)\}([\S\s]*)\{#else\}([\S\s]*)\{\/exist\}/i',
+			'match'=>'/\{([^#\/?_][^}\n]*?)\}/i',
+			'each'=>'/\{#each ([^}]*)\}([\S\s]*)\{\/each \1\}/i',
+			'exist'=>'/\{#exist ([^}]*)\}([\S\s]*)\{\/exist \1\}/i',
+			'existelse'=>'/\{#exist ([^}]*)\}([\S\s]*)\{#else \1\}([\S\s]*)\{\/exist \1\}/i',
 			'ignore'=>'/\{#ignore\}([\S\s]*)\{\/ignore\}/i',
 			'ignored'=>'/\{#ignored (\d+?)\}/i',
 			'gettext'=>"/{_([^,}]+)(?:, ?([^},]+))*\}/i",