JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
* run.php: factor merge out to template.php (now supports both APIs).
[wfpl.git] / template.php
index bbee573..5ac7f80 100644 (file)
@@ -253,7 +253,8 @@ function merge_templates($main, $tem) {
        $subs = top_sub_templates($tem);
 
        foreach($main['pieces'] as $piece) {
-               if(is_array($piece) and !$piece['pieces'] and $subs[$piece['name']]) {
+               $sub = $subs[$piece['name']];
+               if(is_array($piece) and !$piece['pieces'] and $sub and $sub['args'][0] != 'hide') {
                        $piece = $subs[$piece['name']];
                }
                $out['pieces'][] = $piece;
@@ -398,6 +399,21 @@ class tem {
                print($this->run($tem));
        }
 
+       # merge top-level sub-templates of $tem (object) into $this,
+       # supporting both new and old semantics.
+       function merge($tem) {
+               # append expansions to $this->data (old style)
+               $subs = $tem->top_subs();
+               if($subs) foreach($subs as $name => $val) {
+                       $this->append($name, $val);
+                       unset($tem->data[$name]);  # so array_merge() won't overwrite things
+               }
+
+               # merge the data arrays and template trees (new style)
+               $this->data = array_merge($this->data, $tem->data);
+               $this->template = merge_templates($this->template, $tem->template);
+       }
+
        function top_sub_names() {
                return array_keys(top_sub_templates($this->template));
        }