Search This Blog

Sunday, March 2, 2008

Customizing Content Query Webpart

Firstly, Heather Solomon has an excellent article on it.

Part 1: Export Content Query Web part

  • Open it up and search for CommonViewFields
  • Add in Fields that you want; you will need to use the internal name and the type of data.
A good tool is Sharepoint Explorer for WSS

InternalName, DateField

Example: Calendar Properties
EventDate,DateTime; Description,Note; Location,Text; Property_x0020_Unit,Choice

  •  Save the Web Part and Import it back

Part 2: Locate ItemStyle.xsl under XSL Style Sheet

Create your own custom Item Style

<xsl:template name=”CustomStyle” match=”Row[@Style='CustomStyle']” mode=”itemstyle”> <xsl:variable name=”SafeImageUrl”>
<xsl:call-template name=”OuterTemplate.GetSafeStaticUrl”>
<xsl:with-param name=”UrlColumnName” select=”‘ImageUrl’”/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name=”SafeLinkUrl”>
<xsl:call-template name=”OuterTemplate.GetSafeLink”>
<xsl:with-param name=”UrlColumnName” select=”‘LinkUrl’”/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name=”DisplayTitle”>
<xsl:call-template name=”OuterTemplate.GetTitle”>
<xsl:with-param name=”Title” select=”@Title”/>
<xsl:with-param name=”UrlColumnName” select=”‘LinkUrl’”/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name=”LinkTarget”>
<xsl:if test=”@OpenInNewWindow = ‘True’” >_blank</xsl:if>
</xsl:variable>
<table>
<tr>
<td style=”width: 200px”>
<xsl:value-of select=”ddwrt:FormatDate(string(@EventDate),3081, 3)”/></td>
<td valign=”top” rowspan=”3″>
</td> <td class=”linkitem” style=”width: 200px”>
<xsl:call-template name=”OuterTemplate.CallPresenceStatusIconTemplate”/>
<a href=”{$SafeLinkUrl}” mce_href=”{$SafeLinkUrl}” target=”{$LinkTarget}” title=”mailto:%7B@LinkToolTip}”>
<xsl:value-of select=”$DisplayTitle”/></a>
</td>
</tr>
<tr><td rowspan=”3″ align=”left”>
<xsl:value-of select=”ddwrt:FormatDate(string(@EventDate),3081, 4)”/></td>
<td>Location: <xsl:value-of select=”@Location”/></td></tr>
<tr><td >PropertyUnit: <xsl:value-of select=”@Property_x005F_x0020_Unit “/></td></tr>
<tr><td> xsl:value-of select=”@Description” disable-output-escaping=”yes”/></td></tr>
</table>
To see what fields are being passed in<xsl:for-each select=”@*”>P:<xsl:value-of select=”name()” />
</xsl:for-each>
</xsl:template>

If you want to format the Date Time using ddwrt, remember to add   xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" within the tag.
  

1 comment:

  1. Hello Jessica, thanks for your tutorial.

    it workes really good so far, I just stumbled across a problem I cannot solve.

    When I try to resolves fields like Editor or author, it works perfectly by including "Editor,User" in the CommonViewFields Attribute.
    But as soon as I create a Custom User Field, like Username for example, and add "Username,User" in the CommonViewFields, the Content Query Webpart throws an error.
    Am I doing something wrong, or is there a bug with custom userfields?

    Thanks in advance,
    darius

    ReplyDelete