The perfect hierarchy UDT
Posted: Thu Oct 25, 2007 2:21 pm
I've been going through the forums all afternoon looking for a workable {hierarchy} UDT, and all of them seem to have bugs. This one I found works the best:
Except that it returns the current level instead of the parent level in h_parent. Both h_toplevel and h_this work as they should.
Can anyone see why this error is happening, so that we can make a bulletproof {hierarchy} UDT?
Code: Select all
global $gCms;
$pos = $gCms->variables['position'];
$base = explode('.', $pos);
$totalDepth = count($base);
$parentDepth = $totalDepth;
$count = 0;
foreach($base as $parentLevel) {
$parentLevel = ltrim($parentLevel, "0" );
if($count <= $parentDepth) {
$thisLevel .= $parentLevel . ".";
}
if($count < $parentDepth) {
$theParent .= $parentLevel . ".";
}
$count++;
}
$smarty->assign('h_toplevel', $base[0] * 1);
$smarty->assign('h_parent', rtrim($theParent, "." ));
$smarty->assign('h_this', rtrim($thisLevel, "." ));Can anyone see why this error is happening, so that we can make a bulletproof {hierarchy} UDT?