Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Use macro to get top level document name View modes: 
User avatar
Member
Member
gliker-inorbital - 7/26/2011 1:18:09 PM
   
Use macro to get top level document name
Hi guys,

I'm building sidebar menu and I need to insert top level page name at a top of the menu as a title. How I can use macro to get this information? Closest I got is this macro that gets parent node name, but I need to get page name from top most menu in current tree (not home):
{%cmscontext.currentdocumentparent.nodename%}

Also, I tried this
{&{0}&}

and this targeted right page but I need name instead path.

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 7/27/2011 1:19:29 AM
   
RE:Use macro to get top level document name
Hi,

you could create a custom macro for this purpose. The code parse alias path of current node to find alias path of its parent. Then it finds information about the top level node.
case "myparentnode":
match = true;
result = "";
// Tree node
string parentPath = "/" + CMSContext.CurrentAliasPath.Split('/')[0];

if (!String.IsNullOrEmpty(parentPath))
{
CMS.TreeEngine.TreeNode node = null;

// Tree provider
UserInfo ui = UserInfoProvider.GetUserInfo("administrator");
CMS.TreeEngine.TreeProvider tree = new CMS.TreeEngine.TreeProvider(ui);

// Get Single node specified by it`s ID
node = tree.SelectSingleNode(CMSContext.CurrentSiteName, parentPath, "en-us");

if (node != null)
{
result = node.NodeName;
}

}
break;

Best regards,
Ivana Tomanickova

User avatar
Member
Member
gliker-inorbital - 7/27/2011 8:20:57 AM
   
RE:Use macro to get top level document name
Sweet, thanks Ivana!

User avatar
Member
Member
jheavner-ce - 10/17/2012 7:59:48 AM
   
RE:Use macro to get top level document name
You can use the macro engine in version 6 to get the root document name. This is a bit kludgy but it works.
{%
nl = CMSContext.CurrentDocument.NodeLevel;
d = CMSContext.CurrentDocument;
while (nl > 1)
{
d = d.Parent;
nl = d.NodeLevel;
}
return "<a class='lefttopnavhead' href='" + d.NodeAliasPath + "'>" + d.DocumentName;
%}

User avatar
Member
Member
jheavner-ce - 11/25/2013 2:57:21 PM
   
RE:Use macro to get top level document name
I wrote the above. It's awful, in so many ways. Please don't use it. Ever.

If you need to find the root use {&{0}&}. If you need to expose properties then use CurrentPageInfo and NOT CMSContext.CurrentDocument.

User avatar
Member
Member
lwhittemore-emh - 1/29/2014 3:55:02 PM
   
RE:Use macro to get top level document name
Can You elaborate? I am using version 7 and want to create a right menu that gets the root documents name for the title of the menu

Tree Looks like this
Site Root
- Home
- Getting Started
- - Maps
- - Members
- - Weather

So I don't want the site root but the first document. So when you view getting started or any of it's sub pages you see a menu that has getting started as the title with a list of the menu items below. I can get the menu items using the css list menu web part with a the path set to /{0}/% But I want to add a macro in the before content to get the title.

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 1/29/2014 4:58:09 PM
   
RE:Use macro to get top level document name
Hello,

As you can see, this is a forums thread for version 5, so if you are using version 7, please create a new thread under appropriate version.

Thank you for understanding.

Regards,
Martin Danko

User avatar
Member
Member
lwhittemore-emh - 1/29/2014 5:04:11 PM
   
RE:Use macro to get top level document name
No Problem, I was figuring it would be similar to six and it was mentioned above about the macro engine in six.

Here is a link to my post in the 7 forum
http://devnet.kentico.com/Forums/f65/t43646/Root-document-name-macro.aspx