I'm updating a CMSMS website from 1.x to 2.x and there is a User Defined Tag that I need to rewrite.
I have a website with a FAQ: /faq/category/article
Level 1: faq
Level 2: category
Level 3: article
When on a level 3 page I want to display the "title" of the category above it.
This is the OLD UDT code:
Code: Select all
$manager = cmsms()->GetHierarchyManager();
$var = isset($params['assign']) ? $params['assign'] : 'root_page_alias';
$result = "NO RESULT";
$thisPage = $smarty->get_template_vars('content_id');
$currentNode = $manager->sureGetNodeById($thisPage);
while( isset($currentNode) && $currentNode->getLevel() >= 1 )
{
$currentContent =& $currentNode->getContent();
$result = $currentContent->Name();
$currentNode =& $currentNode->getParentNode();
}
echo $result;
This code might be hulpful, it gets the alias of level 2.
Code: Select all
$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)-2]->get_tag('alias');
echo $alias;