“Source” is your friend

The content query web part in SharePoint 2007 is a great tool for rolling up information from subsites into a top level site.   However, sometimes the default look, feel and functionality just doesn’t fit the requirements.   
There is a great MSDN article on how to modify the XSL used by the content query web part to change the way it displays information.   In my case, however, it wasn’t the look that I needed to modify it was the functionality.
I used the content query web part to display a list of announcements from all of my sub-sites.   I set up the web part to display the announcements in a bulleted list, grouped by site.   This simple configuration met my initial requirements.     There was one navigation issue I noticed right away.   If the user clicked on the announcement title in the content query web part they were taken to the view form for the announcement which contains a close button.   When the user clicks the close button they are returned to the list where the announcement is stored, not back to the original top level site.    This simple navigation issue caused all sorts of confusion for the users of the system.   They expected the close button to take them back to where they had started.
This was actually a simple issue to resolve.   I used the methods outlined in the MSDN article to create a new section in the XSL for my new style template.  I based my new style template on the existing bulleted style.   I then made one simple modification to the anchor tag so that my destination url has a source attribute that specifies where the user came from when clicking on the link.   In this case it is /departments/it/default.aspx.
            <a href="{$SafeLinkUrl}&amp;source=/departments/IT/default.aspx" target="{$LinkTarget}" title="{@LinkToolTip}">
I saved the update XSL and checked it into SharePoint.    It was then just a simple process of modifying the settings of the content query web part to use the new template.    Now when a user clicks on one of the links they can return back to where they started by clicking on the close button.
There might be a way to dynamically set the source instead of the static method I used here.   However, this solution met my immediate needs.

Leave a Reply