Note on Customizing Content Query Web Part
Content Query Web Part (CQWP) is a powerful feature in SharePoint, where users can create custom view of data that is queried from various sources, lists, libraries, and present all in one web part. One of my tasks yesterday is to create a content query web part, and query the contents from two sub-sites. Specifically, I have 2 calendars in 2 sub-sites and I have to query all events and combine into a master calendar in the top site (Of course I can make use of the great filtering, sorting and grouping features in CQWP).
After adding the CQWP, my next step is to customize the layout because the default one is too plain. I google and find all these useful articles:
- Display Content Query Web Part Results in a Grid / Table
- Customizing the Content Query Web Part and Custom Item Styles
- How to: Customize XSL for the Content Query Web Part
- How to: Customize the Content Query Web Part by using Custom Properties
- Configuring and Customizing the Content Query Web Part
One of the techniques in customizing CQWP layout is to make use of internal field name and modify CommonViewFields in the exported .webpart file. I follow all steps, modify the .webpart and xsl files as I wish, but I still can't display the content in my CQWP (I can see some other default fields like Title though).
Later, I find the bug is at the key element - CommonViewFields - It does not allow SPACE in the value string. For example:
Wrong: <property name="CommonViewFields" type="string">Title, Text; Description, Note;</property>
Correct: <property name="CommonViewFields" type="string">Title,Text;Description,Note</property>
My note is that we developers cannot add SPACE when typing the value, or even anywhere in the tag. And, we should not add a semi-colon at the end of the string.
P.S. After customizing the layout and fields on the CQWP, we will most probably need to format the field, such as changing the time format of a DateTime field, number of decimal points etc, and here is a very useful reference article: Customizing the Content Query Web Part XSL