I have recently been building alot of new functionality in SharePoint 2013 and wanted to extend my Promoted Links WebPart to enable me to place the WebPart on a publishing website page layout and then have each page display a different set of links depending on which links in the list were tagged. I was able
to easily add a new managed metadata column which used the Managed Navigation Term set for the current site collection as its source so that I was able to select which page to display however I was unable how to change my WebPart to understand what the current pages term was. Having used the Content by Search WebPart I was aware that this has the functionality built so obviously it should be a fairly simple process.
I also know there is an OOTB WebPart called the Term Property WebPart which enables you to display properties based on a specific term or properties based upon the current context. Using this WebPart however would not be an option as there is no connection properties on this WebPart.
To find the solution I dug around the MSDN technical documentation for 2013 and came across the TaxonomyNavigationContext class (http://msdn.microsoft.com/en-gb/library/microsoft.sharepoint.publishing.navigation.taxonomynavigationcontext.aspx) This class was the answer to my problem, and by passing your current context you can easily get the information you need. e.g.
1 |
TaxonomyNavigationContext tnx = TaxonomyNavigationContext.Current; if (tnx.HasFriendlyUrl) { TermTitle = tnx.FriendlyUrlTerm.Title.ToString(); } |
One thing I discovered however is that the Root of the site does not necessarily have a term assigned to it so by checking if there is a friendly url before retrieving will prevent a null exception.