Sharing SharePoint

Always a rookie in the SharePoint World

Customizing Content Query Webpart

Posted by Jessica Wang on March 3, 2008

  

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 

<property name=”CommonViewFields” type=”string”>InternalName, DateField</property>

Example: Calendar Properties 

<property name=”CommonViewFields” type=”string”>EventDate,DateTime; Description,Note; Location,Text; Property_x0020_Unit,Choice</property>

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 <xsl:stylesheet> tag.
  

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: