How to display all fields available in the content query web part (CQWP)
When working with customizing the Content Query Web Part (aka CQWP), you often want to know what you're dealing with. In this article I'm going to show you how you can show all the fields and their contents for all the items being displayed.
There are several suggestions out there on how to accomplish this, but here's my take. This recipe involves editing the style sheets (XSLT) for the CQWP. The CQWP uses three different style sheets for rendering the content set up to be displayed. By default these three are:
- /Style Library/XSL Style Sheets/ContentQueryMain.xsl
- /Style Library/XSL Style Sheets/Header.xsl
- /Style Library/XSL Style Sheets/ItemStyle.xsl
Using SharePoint Designer, open this file. Add the following template text in the bottom of the file (but before the closing tag):
<xsl:template name="ShowXML" match="Row[@Style='ShowXML']" mode="itemstyle">
<xsl:variable name="SafeLinkUrl">
<xsl:call-template name="OuterTemplate.GetSafeLink">
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:variable>
<b>
Item: <i>
<a href="{@LinkUrl}">
<xsl:value-of select="@Title" />
</a>
</i>:
</b>
<ol>
<xsl:for-each select="@*">
<xsl:sort select="name()"/>
<li>
<xsl:value-of select="name()" />
<xsl:text disable-output-escaping="yes"> </xsl:text>
<i>
<xsl:value-of select="." />
</i>
</li>
</xsl:for-each>
</ol>
<br />
</xsl:template>
- Save the file, and do a Check-in.
- Now go back to your page containing your CQWP, Edit Page, and choose Modify Shared Web Part on the CQWP.
- Under the Category Presentation, in the Item Styles dropdown list, now choose your new style called ShowXML. See screen shot below
- Finally, click Apply or OK.
For example of result, see screen shot below.
That's it! There's nothing to it!
But, the point of doing this in the first place is not only to see which fields you have available. You have probably created your own fields you want to use in the CQWP. So, to make them available here, I would like to send you over to Heather Solomons' excellent article on how to accomplish this. Check it out here: Customizing the Content Query Web Part and Custom Item Styles
For more information on how to customize the CQWP and its style sheets, check out my de.icio.us bookmarks on http://feeds.delicious.com/rss/frankove/cqwp. I won't bother posting all the links in this post, since I constantly find new good links. But here are a few good ones:
- Customizing the Content Query Web Part and Custom Item Styles
- Microsoft Enterprise Content Management (ECM) Team Blog : Configuring and Customizing the Content Query Web Part
- How to: Customize XSL for the Content Query Web Part
- Paul Galvin's SharePoint space: Display Content Query Web Part Results in a Grid / Table
1 comment:
Hello Frank,
I have a particular problem regarding the content query webpart, let me know if you can help me out
I want to implement the CQWP to retrieve the last 5 Post of 3 different discussion boards, I have already placed the query correctly and I have modified the ItemStyle.xsl in order to display some more information, the tricky thing is that among this extra fields to display I want to display the # OF REPLIES PER DISCUSSION, and I just havent found out the way to pull this info, seams there is no variable or column with this data.
Thanks for you support
Regards,
Post a Comment