From 8caa06f2e35edfe1d923fc8fcfe732e425b6b475 Mon Sep 17 00:00:00 2001 From: Josh Grams Date: Sat, 22 Aug 2009 13:30:17 -0400 Subject: [PATCH] * run.php: factor merge out to template.php (now supports both APIs). --- run.php | 5 +---- template.php | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/run.php b/run.php index 8e7941e..197dc76 100644 --- 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']; diff --git a/template.php b/template.php index bbee573..5ac7f80 100644 --- a/template.php +++ b/template.php @@ -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)); } -- 1.7.10.4