Tuesday, June 19, 2012

Practical guide to the SharePoint 2010 Content Query Web Part (CQWP)

The Content Query Web Part is one of the most powerful web parts which is provided by the SharePoint Server Publishing Framework (it is not available with SharePoint Foundation). It allows you to roll up information within a SharePoint site collection for display on a web page by letting you build queries through simple configuration of the different available web part properties. The Content Query web part leverages caching and performance optimization techniques and avoids the use of custom code.

While the out of the box CQWP is quite powerful you will see some that in most cases you will need extra configuration and customization. This has however become a lot simpler in SharePoint 2010 by the introduction of slots. So how does this work. Steps to get going:

  • Configure your Content Query web part using the different properties in the web part pane

  • Export the configured Content Query web part to your desktop and modify the .webpart file. Change the ItemXsLink property and point it to the previously uploaded customitemstyle.xsl

<property name="ItemXslLink" type="string">/Style Library/XSL Style Sheets/customitemstyle.xsl</property>

  • Upload the web part definition again and add it to the page. Click “edit web part” and open the web part tool pane. You will notice that within the Presentation> Styles section, you are able to select the newly created itemstyle template that you added in customitemstyle.xsl. After selecting it and clicking apply you will notice that the “CreatedBy” marker that you specified in your custom item style template is now appearing within the tool pane. These markers within the item style are called slots and can be filled with content at runtime.

Once you define slots in the itemstyle.xsl these are picked up by the Content Query Web Part and shown in the web part tool pane so that you can map these to specific fields. Using the “slots” concept you can define reusable XSL templates. This also means that you don’t need to use the “CommonViewfields” property anymore as defined in SharePoint Server 2007 – this is a thing of the past (See Displaying Custom Fields in Content Query Web Parts in Office SharePoint Server 2007)

If you want to delve a little deeper and see some practical examples of the Content Query Web Part check out these links:

No comments:

Post a Comment