Get a page's root parent's alias
Previous article Next articleThis User Defined Tag gets the alias of a pages very top parent. The article originates from the former CMSMS Wiki and the original author is Calguy1000.
Note: Similar functionality is provided by the CGSimpleSmarty module's {cgsimple::get_root_alias()} tag.
Create a new User Defined Tag called "get_root_page_alias" and copy the following code in it:
$alias = \cms_utils::get_current_alias();
$stack = array();
$node = $hm->find_by_tag('alias',$alias);
while( $node && $node->get_tag('id') > 0 ) {
$stack[] = $node;
$node = $node->getParent();
}
if( count($stack) == 0 ) return;
$alias = $stack[count($stack)-1]->get_tag('alias');
echo $alias;
How to use
The tag can be called using:
Working example
I used it in my multilingual template.
Comment Form
ReviewManager
ReviewManager
6 Comments
Could you please tell me how to get the page's 'menu text' instead of the 'alias' for version 2.x ?
http://www.cmsmadesimple.terrarium.pl/de/
 
 how to make it working 
 
 iam here
 http://www.cmsmadesimple.terrarium.pl/de/seite-1/
 and when i click on flag i go to for example
 http://www.cmsmadesimple.terrarium.pl/pl/strona-1/
 
 now when i click on flag i go back to country main page...
@Rolf: Send an E-Mail to above address if you would like to get my code for multilingual search result filtering.
 
 I figured that maybe its best if it just gets here with the rest of your stuff :)
 
 And thanks again for this great website.
* Add parameter "alias". If alias is set, look for that alias' root page alias instead of the current's.
 
 * Reason: I use this for a custom search template to filter out results from other languages. Might be useful in other cases, too.
 
 
 
 
 
 *** CODE ***
 
 $manager = cmsms()->GetHierarchyManager();
 
 $var = isset($params['assign']) ? $params['assign'] : 'lang';
 
 $result = "NO RESULT";
 if ( isset ($params['alias']) ) {
 $currentNode = $manager->sureGetNodeByAlias($params['alias']);
 } else {
 $thisPage = $smarty->get_template_vars('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);
Hi Vinciane,
 I updated the UDT above. Please report back if it solves the problem for you.
 Thanks.
I used it on cmsms 1.11.4 and everything worked well.
 Now I want to use this on cmsms 1.11.7 but even if I change the line 5 $result = "NO RESULT"; into $result = "en";
 I still got and error :
 Strict Standards: Only variables should be assigned by reference in ...www/lib/classes/class.usertagoperations.inc.php(265) : eval()'d code on line 7
 
 Do you think there's something different with the version of cmsms?
 
 Your help is welcome.

