UDT to get parent not root node

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
R0BINH00D
Forum Members
Forum Members
Posts: 19
Joined: Wed Oct 24, 2007 4:32 pm

UDT to get parent not root node

Post by R0BINH00D »

I have this UDT which retreives the root node.

Code: Select all

global $gCms;
global $smarty;

$manager =& $gCms->GetHierarchyManager();

$var = 'root_page_alias';
if( isset($params['assign']) && $params['assign'] != '' )
{
  $var = $params['assign'];
}
$result = "NO RESULT";
$thisPage = $gCms->variables['content_id'];
$currentNode = &$manager->sureGetNodeById($thisPage);
while( isset($currentNode) && $currentNode->getLevel() >= 0 )
{
    $currentContent =& $currentNode->getContent();
    $result = $currentContent->Alias();
    $currentNode =& $currentNode->getParentNode();
}
$smarty->assign($var,$result);
Can anyone help me create a UDT that retrieves the parent?

Thanks

Dan
R0BINH00D
Forum Members
Forum Members
Posts: 19
Joined: Wed Oct 24, 2007 4:32 pm

Re: UDT to get parent not root node

Post by R0BINH00D »

ok,

I have some code - and it works - but I know there must be a better way!

Code: Select all

global $gCms;

$contentops =& $gCms->GetContentOperations();
$smarty =& $gCms->GetSmarty();

$alias = $smarty->get_template_vars('page_alias');
$content =& $contentops->LoadContentFromAlias($alias);
$parentid = $content->ParentId();
$parentalias = $contentops->GetPageAliasFromId($parentid);
return $parentalias;
Any suggestions?

Dan
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

Re: UDT to get parent not root node

Post by Ted »

That's pretty much as good as it gets.  There are a few other ways to do it using the Hierarchy Manager, but that way works just as well.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: UDT to get parent not root node

Post by calguy1000 »

The CGSimmpleSmarty module has this function built in..... and a few other useful ones.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
R0BINH00D
Forum Members
Forum Members
Posts: 19
Joined: Wed Oct 24, 2007 4:32 pm

Re: UDT to get parent not root node

Post by R0BINH00D »

If no one suggests any other code - shall I mark it as solved?

Thanks

Dan
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

Re: UDT to get parent not root node

Post by Ted »

Yes, please do.  Thanks.
Post Reply

Return to “CMSMS Core”