Page 1 of 1

The perfect hierarchy UDT

Posted: Thu Oct 25, 2007 2:21 pm
by stopsatgreen
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:

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, "." ));
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?

Re: The perfect hierarchy UDT

Posted: Thu Oct 25, 2007 2:27 pm
by RonnyK
What is wrong with the {sitemap} to show the hierarchy?

Ronny

Re: The perfect hierarchy UDT

Posted: Thu Oct 25, 2007 2:41 pm
by stopsatgreen
That's only good for displaying a sitemap. The {hierarchy} UDT allows you to get parent, current and top level elements, which is really useful for interacting with the menu.

Re: The perfect hierarchy UDT

Posted: Fri Oct 26, 2007 8:35 am
by stopsatgreen
Can't anyone take a look at this script and tell me why $h_parent is picking up the same value as $h_this?