UDT: Get Level Two Title

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
paulhermans
Forum Members
Forum Members
Posts: 15
Joined: Fri Aug 03, 2018 11:55 am

UDT: Get Level Two Title

Post by paulhermans »

Situation:

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;
UDT: Get_Level_Two_Alias

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;
Does anybody know how to get the corresponding Title?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: UDT: Get Level Two Title

Post by calguy1000 »

https://apidoc.cmsmadesimple.org/classe ... tBase.html

You want the page name.. or the title attribute.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
paulhermans
Forum Members
Forum Members
Posts: 15
Joined: Fri Aug 03, 2018 11:55 am

Re: UDT: Get Level Two Title

Post by paulhermans »

Hi i'm looking for the title attribute of the page one level up in the hierarchy.

Do you know how I can get this value?
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1609
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: UDT: Get Level Two Title

Post by DIGI3 »

CGSimpleSmarty has functions for that, something like:

Code: Select all

{cgsimple::get_page_title(cgsimple::get_parent_alias())}
Should work.
Not getting the answer you need? CMSMS support options
paulhermans
Forum Members
Forum Members
Posts: 15
Joined: Fri Aug 03, 2018 11:55 am

Re: UDT: Get Level Two Title

Post by paulhermans »

Thanks DIGI3, that works, but only if you are at level 3.

Do you also have a solution that gets me the title of level 2 no matter if I am at level 2 or 3?
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1609
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: UDT: Get Level Two Title

Post by DIGI3 »

(cgsimple::get_parent_alias()) gets the parent of the current page. There's also a function for getting the root alias, it's in the CGSS docs.

You can stack them if you're looking for the grandparent, great-grandparent, etc. e.g. (cgsimple::get_parent_alias((cgsimple::get_parent_alias()))) should get the grandparent.
Not getting the answer you need? CMSMS support options
Locked

Return to “CMSMS Core”