Tuesday, May 11, 2010

Customizing Content Query Web Part (CQWP)

Content query web part can be used to pull up data from various sources of data. I am going to show to to pull up data from a list and style the content using this web part.

Step 1: Create a custom list with two fields,  Title and Description and name the list as "About this site". We will be bringing up only one item from this list into our web part.

Step 2: Open Styles Library, from Site Settings -> Site Libraries and Lists and select Customize "Styles Library". Follow the following two images for reference

Step 3: In XSL Style Sheets folder shown above, there is an ItemStyle.xml. This file is used by CQWP when rendering styles for every item. Download this file somewhere onto the drive and copy the following code end of the file inside section and import back into Style Library.

Step 4: Open up the home page of the site where you want the content to be displayed and add a conent query web part from the web part gallery. If you dont find this web part in the gallery, you dont have Publishing and Infrastructure Feature not activated. Content Query Web Part (CQWP) is shown as soon as this feature is activated.

Step 5: We need to modify this web part so that the description will be displayed. So, go ahead and export the web part somewhere onto the drive. Open the .webpart file using noted pad and search for "CommonViewFields" and replace the following line in its entirety.

Description, Text

Step 6: The above changes tells the web part to display a field from the data source and also field type of the column we are trying to display. Now, go ahead save the file and import back onto the page.

Step 7: As soon as the page is refreshed, whatever the data put in the list we created earlier will be displayed with all the formatting applied.

Technorati Tags: ,,,

No comments:

Post a Comment