diff --git a/outputhtml.php b/outputhtml.php index 2fbd211..7a9f24f 100644 --- a/outputhtml.php +++ b/outputhtml.php @@ -5,6 +5,7 @@ */ require_once ("domframework/output.php"); + /** Display in HTML the data provided, with the layout support */ class outputhtml extends output { @@ -59,7 +60,6 @@ class outputhtml extends output "No data provided from view %s::%s"), $viewClass,$viewMethod), 500); - $resView = $resView["content"]; } } @@ -68,7 +68,6 @@ class outputhtml extends output if (! file_exists ($layout) && file_exists ("views/$layout.html")) $layout = "views/$layout.html"; $layoutPage = $this->layoutVariables ($layout, $variable); - $resView = str_replace ("{content}", $resView, $layoutPage); } else { @@ -86,23 +85,33 @@ class outputhtml extends output EOT; - $resView = str_replace ("{content}", $resView, $layoutPage); } + // Do the title replacement in the replacement structure - if (! isset ($replacement["{title}"])) - $replacement["{title}"] = $title; if (! isset ($replacement["{flash}"])) $replacement["{flash}"] = ""; - foreach ($replacement as $key=>$val) - $resView = str_replace ($key, $val, $resView); + $layoutPage = str_replace ($key, $val, $layoutPage); + + // All the entries coming from views in array are substitute in layout + // {content}, {title} + if (is_array ($resView)) + { + foreach ($resView as $key => $val) + { + $layoutPage = str_replace ("{".$key."}", $val, $layoutPage); + } + } + else + $layoutPage = str_replace ("{content}", $resView, $layoutPage); + //echo $resView;exit; // Manage the timestamp/md5sum for the external files managed by this // server. $dom = new \DOMDocument (); - @$dom->loadHTML ($resView); - foreach (array ("script"=>"src", "link"=>"href", "img"=>"src") + @$dom->loadHTML ($layoutPage); + foreach (array ("script" => "src", "link" => "href", "img" => "src") as $key=>$val) { $files = $dom->getElementsByTagName ($key); @@ -146,7 +155,7 @@ EOT; // FIXME : Allow to manage variables in a layout provided in the variable, // without eval use if (! file_exists ($layout)) - return $layout; + return "$layout doesn't exists"; extract ($variables); ob_start(); require ($layout);