• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: UDT: Get Level Two Title
PostPosted: Fri Aug 03, 2018 12:26 pm 
Offline
Forum Members
Forum Members

Joined: Fri Aug 03, 2018 11:55 am
Posts: 15
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:
$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:
$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?


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: UDT: Get Level Two Title
PostPosted: Fri Aug 03, 2018 2:28 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Tue Oct 19, 2004 6:44 pm
Posts: 7959
Location: Fernie British Columbia, Canada
https://apidoc.cmsmadesimple.org/classes/ContentBase.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.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: UDT: Get Level Two Title
PostPosted: Fri Aug 03, 2018 2:42 pm 
Offline
Forum Members
Forum Members

Joined: Fri Aug 03, 2018 11:55 am
Posts: 15
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?


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: UDT: Get Level Two Title
PostPosted: Fri Aug 03, 2018 2:56 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Wed Feb 25, 2009 4:25 am
Posts: 465
Location: Victoria, BC
CGSimpleSmarty has functions for that, something like:

Code:
{cgsimple::get_page_title(cgsimple::get_parent_alias())}


Should work.

_________________
Not getting the answer you need? CMSMS support options


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: UDT: Get Level Two Title
PostPosted: Fri Aug 03, 2018 3:52 pm 
Offline
Forum Members
Forum Members

Joined: Fri Aug 03, 2018 11:55 am
Posts: 15
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?


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: UDT: Get Level Two Title  Topic is solved
PostPosted: Fri Aug 03, 2018 9:28 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Wed Feb 25, 2009 4:25 am
Posts: 465
Location: Victoria, BC
(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


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
A2 Hosting