Get a page's root parent's alias

  Previous article Next article  

Get a page's root parent's alias

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.1.6
  Last updated: 21-01-2017
  Comments: 6

This 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:

$assign = isset($params['assign']) ? $params['assign'] : 'root_page_alias';

$hm = cmsms()->GetHierarchyManager();

if ( empty($alias) ) $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');

$smarty->assignGlobal($assign,$alias);

  How to use

The tag can be called using:

{get_root_page_alias}
<p>The root parent of this page is: {$root_page_alias}</p>
{get_root_page_alias assign=foo}
<p>The root parent of this page is: {$foo}</p>

  Working example

I used it in my multilingual template.


A2 Webhosting CMS Made Simple

  Comments

  Click here to leave a comment






This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)
  « Enter the CAPTCHA code (lower case)

Your IP address will be stored on submit. I reserve the right to change or delete your response without notice!
In case of abuse your IP address will be blocked!


Can I have your attention for a moment?

Did this tutorial help you solving a problem at your (clients) website and it saved you many hours of work? Great!!
Consider buying Rolf a cup of coffee in return! [ Click here ]


  6 Comments

CMS Made Simple 2.2.3.1 - Tutorials, tips and tricks - CMSMS 2.2.3.1

Get a page's root parent's alias

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.1.6
  Last updated: 21-01-2017
  Comments: 6

A2 Webhosting CMS Made Simple