Page 1 of 1

[solved] how to get a title of the parent page?

Posted: Sun Sep 02, 2007 6:50 pm
by liudaz
Hello,

I have been surfing the forum for some time to find the solution for my problem and i ended up in a dead end.

I am using the template "Top simple navigation + left subnavigation + 1 column". There is first level menu on the top, and second level submeniu in the sidebar.
1.About Us
1.1 Address
1.2 Phone
2. Who We Are
3. What We Do
If i press "address" or "phone" i still want to have a title (in this case it is "about us") above the subnavigation.
I believe modificationt of {breadrumbs} could do that, but too bad it doesnt have the "end-level" parameter. :(

I appresiate your help. :)

Liudas

Re: how to get a title of the parent page?

Posted: Sun Sep 02, 2007 7:01 pm
by calguy1000
Remind me on tuesday.  I have a UDT to get the page alias of the parent page.... You could use this, in conjunction with another UDT to get the page title of a page given the alias.

Re: how to get a title of the parent page?

Posted: Sun Sep 02, 2007 7:23 pm
by liudaz
Will do so. Thank you in advance.  ;)

Re: how to get a title of the parent page?

Posted: Tue Sep 04, 2007 1:30 am
by AmandaBTO
What great timing!  I could really use this too :)

Re: how to get a title of the parent page?

Posted: Tue Sep 04, 2007 3:28 pm
by Dr.CSS
Maybe this thread, found using search "title of parent page"...

http://forum.cmsmadesimple.org/index.ph ... 778.0.html

Re: how to get a title of the parent page?

Posted: Tue Sep 04, 2007 3:43 pm
by calguy1000
Here's a UDT I call get_root_alias.

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;
}
Next, getting the title of a page, given a page alias should be as simple as a UDT like this:

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;
So in total, to get the title of the top level parent:

Code: Select all

{get_root_alias alieas=$page_alias assign='root_alias'}{get_page_title alias=$root_alias}
Now, this second tag is untested, but it should be pretty close.

Re: how to get a title of the parent page?

Posted: Tue Sep 04, 2007 5:19 pm
by AmandaBTO


Sweet assed!


Re: how to get a title of the parent page?

Posted: Tue Sep 04, 2007 6:37 pm
by liudaz
Works just like i wanted. Thank you very much! ;)