# 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'];
$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;
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));
}