The perfect hierarchy UDT

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
stopsatgreen
Power Poster
Power Poster
Posts: 322
Joined: Sat Feb 04, 2006 1:24 am

The perfect hierarchy UDT

Post 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?
RonnyK
Support Guru
Support Guru
Posts: 4962
Joined: Wed Oct 25, 2006 8:29 pm

Re: The perfect hierarchy UDT

Post by RonnyK »

What is wrong with the {sitemap} to show the hierarchy?

Ronny
stopsatgreen
Power Poster
Power Poster
Posts: 322
Joined: Sat Feb 04, 2006 1:24 am

Re: The perfect hierarchy UDT

Post 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.
stopsatgreen
Power Poster
Power Poster
Posts: 322
Joined: Sat Feb 04, 2006 1:24 am

Re: The perfect hierarchy UDT

Post 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?
Post Reply

Return to “CMSMS Core”