API Questions on Kentico API.
Version 6.x > API > Get parent page's title conditional on child nodes View modes: 
User avatar
Member
Member
eneame - 5/30/2012 1:56:34 PM
   
Get parent page's title conditional on child nodes
I am converting an aspx page to be used as a template page in Kentico CMS (6). On the page, I have a menu with a title displayed above. If the current page has a parent page, I would like the title to be the name of the parent page. If not, then I would like the title to be the name of the current page. Also, the items the menu displays are conditional based on whether or not the current page has child pages. Here is my code for the original aspx page...can anyone point me in the right direction to make this work correctly with the Kentico API?


if (!IsPostBack)
{
string sURL = Request.Url.ToString().ToLower();
if (sURL.EndsWith("default.aspx"))
{
if (SiteMap.CurrentNode.HasChildNodes)
{
contentNavHeading.Text = SiteMap.CurrentNode.Title;
subMenuDataSource.StartingNodeOffset = 0;
}
else {
contentNavHeading.Text = SiteMap.CurrentNode.ParentNode.Title;
subMenuDataSource.StartingNodeOffset = -1;
}
}
else
{
contentNavHeading.Text = SiteMap.CurrentNode.ParentNode.Title;
subMenuDataSource.StartingNodeOffset = -1;
}
}


Thank you

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 6/3/2012 5:07:48 AM
   
RE:Get parent page's title conditional on child nodes
Hi,

for this you can use some navigation web part which display nodes. Now to display title of parent you can use Content before property, where you can place macro:

1. Example A

You have structure:
/About
/About/about-car


{(0)%nodelevel|(equals)1|(truevalue){(1)%nodename%(1)}|(falsevalue){(2)%cmscontext.currentdocumentparent.nodename%(2)}%(0)}

The macro displays node name if you are on the first level document (About) and node name of parent if you are on the second level document (Management Team).

For example this macro will not work if your menu web part will be inserted in the root template.


2. Example B

In case you have more complex menu structure you can write a custom macro

Then you can find inspiration in the following thread:
http://devnet.kentico.com/Forums.aspx?forumid=45&threadid=22077

The syntax is a little different in 6.0 version, but if you check the first link, I am sure you will see differences.

Best regards,
Ivana Tomanickova