Page 1 of 1

Getting a page's root parent's alias

Posted: Sun Sep 17, 2006 12:00 am
by binarybee
I needed a way to get the alias of a pages very top parent and calguy1000 on the IRC channel assisted me.

The code he has come up with is as follows...

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);
Create a new user-defined tag called get_root_page_alias and copy in the above code.

The tag can be called using...

Code: Select all

{get_root_page_alias assign="varname"}
An example use would be...

Code: Select all

{get_root_page_alias assign="root_page_alias"}The root parent of this page is:{$root_page_alias}

Re: Getting a page's root parent's alias

Posted: Sun Sep 17, 2006 12:39 pm
by Dee

Re: Getting a page's root parent's alias

Posted: Wed Sep 27, 2006 9:01 am
by haapati
This code doesn't work? I have CMSMS version 0.13. When I put the tag into the template code it stop printing after that.

Re: Getting a page's root parent's alias

Posted: Wed Sep 27, 2006 9:03 am
by Dee
I think this will only work on 1.0.

Re: Getting a page's root parent's alias

Posted: Wed Sep 27, 2006 9:14 am
by haapati
Yes, I just noticed the same thing.

So, I made a code which will work in version 0.13.

Code: Select all

global $gCms;
global $smarty;

$manager =& $gCms->GetHierarchyManager();
$thisPage = $gCms->variables['content_id'];
$node =& $manager->sureGetNodeById($thisPage);


$node_data = (get_object_vars($node));
$parent_node = (get_object_vars($node_data[parentNode]));
$parent_node_content = (get_object_vars($parent_node[content]));

echo $parent_node_content[mAlias];
This print page's root parent alias.

Re: Getting a page's root parent's alias

Posted: Tue Nov 14, 2006 1:12 am
by ostricized
Is it possible to get the root page title?

Re: Getting a page's root parent's alias

Posted: Thu Nov 16, 2006 3:41 pm
by nils73
Do you mean as a tag or the title-attribute of the root-page? As far as I know you can get the title-attribute if it is set.

Regards,
Nils

Re: Getting a page's root parent's alias

Posted: Sun Nov 19, 2006 1:56 am
by ostricized
Hi Nils73!

I am looking for the root page title value (attribute?), more specifically, the magic syntax to obtain that value just like what the 2 examples in this thread accomplish.

Thank you very much in advance if anyone is willing to part with this information =)

Re: Getting a page's root parent's alias

Posted: Sun Nov 19, 2006 2:34 pm
by nils73
ostricized,

you can use all values out of MenuManger, so the title-attribute should be obtained like this:

1. Create a user-defined tag called "get_parent_title" with following values

Code: Select all


global $gCms;
global $smarty;

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

$var = 'root_page_title';
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->Titleattribute();
    $currentNode =& $currentNode->getParentNode();
}
$smarty->assign($var,$result);

2. Put the following code into your website:

Code: Select all


{get_title assign="root_page_title"} The root parents' title of this page is:{$root_page_title}

This should do the trick.

Regards,
Nils

Re: Getting a page's root parent's alias

Posted: Tue Nov 06, 2007 10:54 pm
by calguy1000
Four new methods in the CustomContent module do this:

$ccuser->get_parent_alias($alias = '')  get_root_alias($alias = '') get_page_title($alias = '') has_children($alias = '')  <-- output a boolean indicating if the specified page has children (use current page if no page is specified)

Just thought I'd let you know.

Re: Getting a page's root parent's alias

Posted: Thu Apr 10, 2008 2:45 pm
by joecannes
I've inserted the code for getting the parent title, still not working...I am using CMSMS 1.2.3, and I do have the title defined.

All I get is:

The root parents' title of this page is:

and then it is blank