Much of my job as a SharePoint consultant working in the Web Content Management discipline is the configuring of web parts. One of the most popular web parts has to be the Content Query Web Part. This web part allows you to roll up different kinds of content at the site collection, site, or list level and have full control of the styling of the rollup list through XSL.
Although the Content Query Web Part is very easy to use, it can be challenging getting all of the information available which is what this blog article is all about. By default, fields such as Title, Descriptions, and URL are provided by default. The challenge arises when you need to display more information than what the default fields provide. An example of this would be the case where a custom date field, let’s call it NewDate, would need to be included as part of the rollup.
Now, if we tried to call NewDate directly from the XSL, it would simply print out nothing. This is because the web part doesn’t know about NewDate.
To do this, we need to configure the web part to tell it about our New Field.
This is a simple x step process.
- First, you will need to export the web part so that its properties can be edited.
In edit mode on the CQWP, select Edit -> Export
- After opening the exported file, locate the CommonViewFields property.
By default, it will be blank. Adding additional fields to this property will make them available for display.
- To continue with the example, we will need to add our new field, NewDate, to the CommonViewFields property. The format of this property is [Internal Field Name],[Data Type Name]. It is important to note that the name is the internal field name and not necessarily the name you gave to the list. The best way to determine the internal field name is to go to the List or Content Type settings and click on the new field. The internal field name will be the last query string argument in the URL.
In our example, you would add "NewDate,DateTime" to the property as shown below:
In this example, our field type is DateTime. For a complete list of field types, see this MSDN article: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldtype.aspx
- The final step is to save the web part file and import back into the page. The field, NewDate, is now available and can be successfully referenced in the appropriate XSL files.