Re: Sigma and nested blocks: replace outer block by inner one
| From: | Markus Ernst | Date: | Thu, 15 Dec 2005 18:17:26 +0000 |
| Subject: | Re: Sigma and nested blocks: replace outer block by inner one | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-22260@lists.php.net to get a copy of this message | ||
Markus Ernst schrieb:
Now I need to find a way to hide the level 1 part in some cases, but still show the level 2 part.Uff, sorry for this monologue! I spent a day on it and did not find the solution yet... but actually the problem looks clearer now: This kind of template (no nesting) is no problem: <!-- BEGIN navigation_1 --> <div class="mainnavi"><a href="{href1}">{name1}</a></div> <!-- END navigation_1 --> <!-- BEGIN navigation_2 --> <div class="subnavi"><a href="{href2}">{name2}</a></div> <!-- END navigation_2 --> The problem occurs in the nested template: <!-- BEGIN navigation_1 --> <div class="mainnavi"><a href="{href1}">{name1}</a></div> <!-- BEGIN navigation_2 --> <div class="subnavi"><a href="{href2}">{name2}</a></div> <!-- END navigation_2 --> <!-- END navigation_1 --> If there is no output for the level 1 navigation element, the level 2 element will be output with the first template, but not with the second one. I need a solution that works the same for both kinds of templates. The output function is now easier: function output_navigation($structure, $level=0) {
global $tpl;
$mainblock = "navigation_".($level+1);
$subblock = "navigation_".($level+2);
foreach ($structure as $id => $entry) {
// recursively parse sub blocks
if (isset($entry['subpages']) && !empty($entry['subpages']) && $tpl->blockExists($subblock)) {
output_navigation($entry['subpages'], $level+1);
}
// parse main block
if ($tpl->blockExists($mainblock) && $entry['hide'] === false) {
$tpl->setCurrentBlock($mainblock);
$tpl->setVariable(array('name'.$level => $entry['name'], 'href'.$level => $entry['href']));
$tpl->parseCurrentBlock($mainblock);
}
else {
// how make sure that sub block will be output anyway???
}
}
}
Like this, a nested sub block will be output with the following main block, if the actual main block is hidden. If there would be a replaceBlock() solution, I assume it would cause the sub block to be output in the wrong place if the blocks were not nested. So I look for something like touchBlock(), but with the effect that the block is output regardless of the output of the containing block, if they are nested.
Ouf, I hope this is somehow understandable...
Still appreciate any hint!!
Thanks
Markus