ShowLink Title extension

Just something little that might be of use is an xslExtension to display Titles and Titles as tooltips.

Created a ShowTitle.cs class that gets passed an Item’s ID as a string then fetches title fields; Navigation Title, or Page Title (if Navigation Title is blank), or finally the Name of the Item if both Navigation and Page Title fields are blank.

public static string DisplayTitleLink(string PageID)
{
string PageTitle = "";
string NavigationTitle = "";

Item page = Database.GetDatabase("master").GetItem(PageID);

PageTitle = page.Fields["Page Title"].ToString();
NavigationTitle = page.Fields["Navigation Title"].ToString();

if (NavigationTitle != "")
return NavigationTitle + ". ";

else if (PageTitle != "")
return PageTitle + ". ";

else
return page.Name;
}

Included this extension in the web.config file:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<xslExtensions>
<extension mode="on" type="Proj.Common.ShowTitle, Proj.Common" namespace="http://www.sitecore.net/km" singleInstance="true"/>
</xslExtensions>
</sitecore>
</configuration>

In the XSL stylesheet:

<sc:link text="{km:DisplayTitle($itemID)}" title="{km:DisplayTitleLink($itemID)}"></sc:link>

So now when my link displays it includes a “. ” after as the tooltip - this is handy for renderings such as Left Navigation or Breadcrumb for example that require proper tooltips, rather than have an extra template in the XSL stylesheet to check for Page titles.