JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
* run.php: factor merge out to template.php (now supports both APIs).
authorJosh Grams <josh@qualdan.com>
Sat, 22 Aug 2009 17:30:17 +0000 (13:30 -0400)
committerJosh Grams <josh@qualdan.com>
Sat, 22 Aug 2009 17:30:17 +0000 (13:30 -0400)
run.php
template.php

diff --git a/run.php b/run.php
index 8e7941e..197dc76 100644 (file)
--- a/run.php
+++ b/run.php
@@ -155,10 +155,7 @@ function run_php($dest = false) {
                        # site, copy all template sections that have been show()n to the
                        # site-wide template
                        if($GLOBALS['wfpl_template']) {
-                               $sections = tem_top_subs();
-                               if($sections) foreach($sections as $name => $val) {
-                                       $GLOBALS['wfpl_main_template']->append($name, $val);
-                               }
+                               $GLOBALS['wfpl_main_template']->merge($GLOBALS['wfpl_template']);
                        }
 
                        $GLOBALS['wfpl_template'] = $GLOBALS['wfpl_main_template'];
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));
        }