Page 1 of 1

UDT to get parent not root node

Posted: Thu Dec 20, 2007 10:11 am
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

Re: UDT to get parent not root node

Posted: Thu Dec 20, 2007 11:38 am
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

Re: UDT to get parent not root node

Posted: Thu Dec 20, 2007 1:09 pm
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.

Re: UDT to get parent not root node

Posted: Thu Dec 20, 2007 2:11 pm
by calguy1000
The CGSimmpleSmarty module has this function built in..... and a few other useful ones.

Re: UDT to get parent not root node

Posted: Fri Dec 21, 2007 11:23 am
by R0BINH00D
If no one suggests any other code - shall I mark it as solved?

Thanks

Dan

Re: UDT to get parent not root node

Posted: Fri Dec 21, 2007 1:36 pm
by Ted
Yes, please do.  Thanks.