Saturday, March 1, 2008

Pushing out your content across a SharePoint Internet Site

This is one feature I find every decent CMS should have. The simple ability to create a content item and then push it out to different areas of the website. Sadly enough MOSS does not do this out of the box. It is built on a Pull concept. I.e. you put a content query web part on another page and then start filtering it down to the items you want.
But what if you want one list with links to ten different areas of the website? Sure. Content Types will come in handy. Or even Summary Link Lists.
But often you will want to be very specific about where your content will appear when creating it and not go over the whole site and start adding new filter criteria to all your exisitng CQWPs or maintain loads of link lists.

One solution I found to this problem is using a combination of Summary Links and Content Query Web Parts. Build a Summary Link List into the Content Type that acts for your News. Now only show this list when in Edit Mode. Because we'll be using it as a reference list.
Once you have created your item start adding links to that list to all the different pages where you want your news to appear. -

Finally, and this is the tricky part, place a content query webpart into the pagelayout of your pages, or preferrably even the master page. Modify this Webpart now to use a custom Search query instead of the built in one and add the current URL of the page into the query expression. Effectively you're searching for all content where it can find the current url in the summary links. If it finds it, bingo, it will appear in the list.

A couple of hurdles to watch out for:
  • You can't add web parts to the master page. you will have to embedd the actual Server control into the masterpage if going down that route.
  • When trying to add the current URL you will need to do some server side scripting. Make sure that your trust levels are in order so that the code in the pagelayour ot master page is executed. Some Web.config tweaking will be required.
  • When modifying Content Query Webparts I have found the SharePoint Designer to be my best friend. Fast and effective plus Intellisense.

Tip: first try your luck with a WSS Page or a MOSS Page that you have detached from the Pagelayout. That way you'll be able to get the custom Content Query Webpart up and running much faster.