I’m writing this article over my Thanksgiving holiday so I might as well take a moment to give thanks for things that have been awesome in 2010. I have many things I should be thankful for, like family and friends or perhaps that this is the last official thing I need to write in 2010 (for more info on this, here’s a shameless plug for my new book on Amazon) but since this is a SharePoint article, I’ll focus on something that’s been improved in SharePoint 2010.
The Content Query Web Part is one of the “Swiss Army knives” that comes with SharePoint Server. It has always been very helpful for rolling up lists and pages easily. For SharePoint 2010, there are a couple new features that make it even more useful.
New Query Filters
Filters have always existed for the Content Query Web Part, but SharePoint 2010 adds a couple of new options that are extremely powerful. Rather than filtering a column on a specific value, you can now filter by either PageFieldValue or PageQueryString.
PageFieldValue filters the Content Query Web Part by other fields on the page. This means you can place the same Web Part on several pages and see different items in the rollup based simply on the content of a field on that page. The syntax for this filter would be [PageFieldValue: field name].
Alternatively, PageQueryString filters the Content Query Web part by parameters that are sent over the URL. The syntax for this filter is [PageQueryString: query string parameter name]. This filter can be quite useful for making a rollup page seem more interactive than usual.
For instance, you could create a Content Query Web Part that is filtered by a PageQueryString of “category,” and then you could create a page with links that pass over different query strings on the URL like this: <a href=”cqwp_page.aspx?category=2″>. The Content Query Web Part will then filter results and only show those that match the category that is sent over on the URL.
With both of these filters, if a null value is encountered (for instance, if no query string is sent over), the Content Query Web Part will not apply the filter.
Fields to Display
This next new feature of the Content Query Web Part will really only make 100% sense if you are familiar with how item styles are applied to the Web part with XSLT. If you are used to working with this in SharePoint 2007, you probably remember having to export the Web part file and edit the XML to include CommonViewFields. This was required for showing most custom columns that were being rolled up.
In SharePoint 2010, you no longer need to do this step. Instead, when an item style is applied to a Content Query Web Part, the XSLT is analyzed for any values that are being displayed. These values are shown in the Web part menu as “slots” that can be used in the Fields to Display section. You can show any column that is available to the rollup in any of these the slots. You can even specify more than one value for each slot, and the Web Part will skip any blank values and use the first available non-blank value. This new feature means that the XSLT can be used just for the layout out the rollup, while the values that show can be controlled from the Web Part itself.
When you add these new features to the already impressive list of things that the Content Query Web Part can do, it really adds up to something to be thankful for this holiday season.
Randy Drisgill is a Microsoft SharePoint Server MVP and a consultant with SharePoint911.