Tag Archives: CQWP

Content Query Web Parts

15 Mar

Just a reminder of how to configure & edit these – I’ve not done it in a long time…

MSDN info is at http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.publishing.webcontrols.contentbyquerywebpart.aspx

The display XSL is /Style Library/XSL Style Sheets/ItemStyle.xsl. It’s an OOTB file – the CQWP can be configured to look at a different XSL file but quick fixes mean adding templates to it (normal terms & conditions apply).

So, to configure item display, add a template into the file, here’s one that shows all the fields available:

<xsl:template name="templateName" match="Row[@Style=templateName]" mode="itemstyle">
    <xsl:for-each select="@*">
        <b><xsl:value-of select="name()" /></b><i><xsl:value-of select="." /></i><br/>
    </xsl:for-each>
    <hr/>
</xsl:template>

This can be selected in the drop-down of the web part properties..

Bonus points are for

Formatting dates

Add an attribute to the <xsl:stylesheet> element

xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"

In the item style, use the FormatDateTime function

<xsl:value-of select="ddwrt:FormatDateTime(@Created, 1033, 'dd MMM yyyy')" />

Date and time format string definitions are at http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.90).aspx

Putting the templates in a separate XSL file

Copy & rename the XSL files required for ItemXSL and MainXSL.

Export the web part, then edit the .webpart file and provide new server relative url paths to ItemXSLLink and MainXSLLink properties to use the custom XSL files.

Add additional fields to the output

Export the web part, then edit the .webpart file & update the CommonViewFields property

<property name="CommonViewFields" type="string">InternalColumnNameGoesHere, FieldType</property>

Where FieldType is one of

  • Text
  • Note
  • Number
  • Currency
  • Integer
  • Boolean
  • DateTime
  • Threading
  • Lookup
  • Choice
  • URL
  • Counter
  • DisplayOnly
  • RichHTML
  • Image

Subtle issue with anonymous users

The CQWP can throw errors for anonymous users, when authenticated users can see the web part fine.

It’s documented at http://blog.mastykarz.nl/inconvenient-sharepoint-2010-content-query-web-part-anonymous-access/ with a workaround (columns added to the web part CommonViewFields property).