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
