Sfoglia il codice sorgente

* Properly fix template each
* If a compiled template fails to execute one, attempt recompiling and running again

Nathaniel van Diepen 7 anni fa
parent
commit
789abdf569
1 ha cambiato i file con 7 aggiunte e 2 eliminazioni
  1. 7 2
      Data/template.class.php

+ 7 - 2
Data/template.class.php

@@ -48,7 +48,12 @@
 			if(!file_exists($this->path)){
 				file_put_contents($this->path, static::compile($this->template));
 			}
-			$output = static::execute($this->path, $data);
+			try{
+				$output = static::execute($this->path, $data);
+			}catch(Exception $e){
+				file_put_contents($this->path, static::compile($this->template));
+				$output = static::execute($this->path, $data);
+			}
 			if($this->fire('after', $output) === false){
 				throw new Exception("Render on template {$this->name} cancelled. After");
 			}
@@ -72,7 +77,7 @@
 			$output = preg_replace_callback(static::$regex['each'], function($matches){
 				$output = "<?php if(isset(\$data[".var_export($matches[1], true)."])): ";
 				$output .= "foreach(\$data[".var_export($matches[1], true)."] as \$item): ";
-				$output .= "\$parent[] = \$data; ?>";
+				$output .= "\$parent[] = \$data; \$data = \$item; ?>";
 				$output .= static::compile($matches[2]);
 				$output .= "<?php \$data = array_pop(\$parent);";
 				$output .= "endforeach;endif; ?>";