Re: Sigma and nested blocks: replace outer block by inner one
| From: | Markus Ernst | Date: | Thu, 15 Dec 2005 14:40:06 +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-22258@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. I try to do this with the replaceBlock method, but there seems to be a mistake in my approach.I got one step further by returning the block contents of a sub-block to the main-block processing: function output_navigation($structure, $level=0) {
global $tpl;
$sub_cont = "";
foreach ($structure as $id => $entry) {
$mainblock = "navigation_".($level+1);
$subblock = "navigation_".($level+2);
// recursively parse subblocks and get contents
if (!empty($entry['subpages']) && $tpl->blockExists($subblock)) {
$sub_cont = output_navigation($entry['subpages'], $level+1);
}
if ($tpl->blockExists($mainblock)) {
$tpl->setCurrentBlock($mainblock);
// Try to hide the main entry:
// replace the mainblock by the subblock
// That's what does not work...
if ($entry['hide'] == true && $sub_cont != "") {
$tpl->replaceBlock($mainblock, $sub_cont, true);
$tpl->touchBlock($mainblock);
}
else {
$tpl->setVariable(array('name'.$level => $entry['name'], 'href'.$level => $entry['href']));
$tpl->parseCurrentBlock($mainblock);
}
}
}
// return contents
return $tpl->get($mainblock);
}
Now I can get the subblock contents, but there will be no more processing after $tpl->replaceBlock is called for the first time. So the $keepContent parameter seems to work only for contents that was added to the block before replaceBlock was called.
Is there a way to apply replaceBlock only to the actual loop, and not to the whole block? I would highly appreciate any idea on this!
Thanks
Markus