[solved] How to make "get_root_page_alias" printing the "Title" of the root page

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
nilson
Forum Members
Forum Members
Posts: 15
Joined: Wed Apr 23, 2008 8:52 am

[solved] How to make "get_root_page_alias" printing the "Title" of the root page

Post by nilson »

Dear all,
I want to print the menu text of the parent of the current site. I found the tag "get_root_page_alias"

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);
It works fine. However, I do not want it to print the root-page-alias but rather the text I entered as page title.

Since I'm not familiar with PHP my try of changing line 17

Code: Select all

    $result = $currentContent->Alias();
into

Code: Select all

    $result = $currentContent->Title();
only got me an error.  ???

What else should I try?
Thanks, nilson
Last edited by nilson on Thu Nov 20, 2008 12:16 am, edited 1 time in total.
Andor
Forum Members
Forum Members
Posts: 49
Joined: Sun Feb 19, 2006 1:42 pm

Re: How to make "get_root_page_alias" printing the "Title" of the root page

Post by Andor »

Hi,
Not being an expert at all when it comes to Smarty or php, I found a solution in the forum for what I believe you are looking for.

It combines two UDTs in my template:

Code: Select all

{get_root_alias alias=$page_alias assign='root_alias'}{get_page_title alias=$root_alias}
The code for each of them:

The get_root_alias UDT

Code: Select all

/* Get the alias of the top level parent 
    Takes a page alias as input
    outputs a page alias, or an empty string if the alias input is a top level
    use it like this:  {get_root_alias alias=$page_alias assign='root_alias'}
*/

if( !isset($params['alias']) ) return;

global $gCms;
$contentops =& $gCms->GetContentOperations();

$alias = '';
$id = $contentops->GetPageIDFromAlias( $params['alias'] );
while( $id != -1 )
  {
     $content =& $contentops->LoadContentFromId( $id );
     if( is_object( $content ) ) {
        $alias = $content->Alias();
        $id = $content->ParentId();
     }
  }

if( isset($params['assign']) )
{
  $smarty =& $gCms->GetSmarty();
  $smarty->assign( $params['assign'], $alias );
  return;
}
else 
{
  return $alias;
}
The get_page_title UDT

Code: Select all

/* get the page title of any page, given an alias 
    call it like this:  {get_page_title alias=$root_alias}
*/
if( !isset($params['alias']) ) return;

global $gCms;
$contentops =& $gCms->GetContentOperations();
$contentobj = $contentops->LoadContentFromAlias( $params['alias'] );
$title = $contentobj->Name();

if( isset( $params['assign'] ) )
  {
     $smarty =& $gCms->GetSmarty();
     $smarty->assign($params['assign'],$title);
     return;
   }
return $title;
I have to admit that I didn't dig into how it actually works once I realized that it actually does work ;)

As I said, I found this solution on the forum - I don't remember if I combined several suggestions or if it's a straight copy and paste from one helpful individual. Anyway, if it works for you, don't thank me...

Good luck :)
Last edited by Andor on Wed Nov 19, 2008 11:52 pm, edited 1 time in total.
nilson
Forum Members
Forum Members
Posts: 15
Joined: Wed Apr 23, 2008 8:52 am

Re: How to make "get_root_page_alias" printing the "Title" of the root page

Post by nilson »

Andor,
great! It works perfectly well. No thanks, as you liked it  ;)
nilson
Andor
Forum Members
Forum Members
Posts: 49
Joined: Sun Feb 19, 2006 1:42 pm

Re: [solved] How to make "get_root_page_alias" printing the "Title" of the root page

Post by Andor »

Fantastic!

I guess you feel the same way I do when finding solutions here - that's what so great with the help on this forum :)

'Nilson' - Swede, by any chance?
nilson
Forum Members
Forum Members
Posts: 15
Joined: Wed Apr 23, 2008 8:52 am

Re: [solved] How to make "get_root_page_alias" printing the "Title" of the root

Post by nilson »

nope, German
Locked

Return to “Modules/Add-Ons”