Bienvenue à Blogs CodeS-SourceS Identification | Inscription | Aide

Le petit blog de Pierre / Pierre's little blog

Sharepoint, .NET, IW (Information Worker) solutions, pour le fun et le partage / for fun and sharing Pierre VIVIER-MERLE - MVP SharePoint

Applications I Like

I, Pierre :-)

[SharePoint 2010] custom Content Query WebPart – How to display the last documents in a proper way

Hi all !                                                          (Voir la version française)

A little post regarding customization of the Content Query WebPart (CQWP) in SharePoint Server 2010. This customization allows to use the content query webpart to display documents in a proper way.

It is true that by default, the CQWP is more specialized on news content display, as explained in the following blog What’s New with the Content Query Web Part : http://blogs.msdn.com/b/ecm/archive/2010/05/14/what-s-new-with-the-content-query-web-part.aspx. In my case, I would like to use the webpart to display documents with title, modification date and author of the document.

I will demonstrate it by adding a template in the ItemStyle.xsl file.

1. To find this file, use SharePoint Designer 2010 and go to All Files > Style Library > XSL Style Sheets

2. Copy the entire node named <xsl:template name=“WithDocIcon” /> :

3. Paste it after the node in order to duplicate it

4. Rename the first line to <xsl:template name="ForDocuments" match="Row[@Style='ForDocuments']" mode="itemstyle">
(or any other name)

5. After the node <xsl:variable name="DisplayTitle"/>, add the following one:

<xsl:variable name="DisplayAuthor">
     <xsl:call-template name="OuterTemplate.GetTitle">
         <xsl:with-param name="Title" select="''"/>
         <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
         <xsl:with-param name="UseFileName" select="1"/>
     </xsl:call-template>
</xsl:variable>

It will add one more column as a setting in the property panel of the CWQP (see below)

6. Change the last <div /> to :

<!--<div class="description">-->
        | <xsl:value-of select="@Description" /> - <xsl:value-of select="@Author" />
<!--</div>—>

7. Save it and publish it. Note that the file won’t be no more bound to the site definition

8. Add a content query webpart and set it like that:

9. It will display the following webpart like that:

Note: Please find below the entire xsl template:

<xsl:template name="ForDocuments" match="Row[@Style='ForDocuments']" mode="itemstyle">
     <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="''"/>
              <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
              <xsl:with-param name="UseFileName" select="1"/>
          </xsl:call-template>
     </xsl:variable>
     <xsl:variable name="DisplayAuthor">
          <xsl:call-template name="OuterTemplate.GetTitle">
              <xsl:with-param name="Title" select="''"/>
              <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
              <xsl:with-param name="UseFileName" select="1"/>
          </xsl:call-template>
     </xsl:variable>

     <div class="item link-item">
         <xsl:if test="string-length(@DocumentIconImageUrl) != 0">
             <div class="image-area-left">
                 <img class="image" src="{@DocumentIconImageUrl}" title="" />
             </div>
         </xsl:if>
         <div class="link-item">
             <xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/>
             <a href="{$SafeLinkUrl}" title="{@LinkToolTip}">
                 <xsl:if test="$ItemsHaveStreams = 'True'">
                   <xsl:attribute name="onclick">
                     <xsl:value-of select="@OnClickForWebRendering"/>
                   </xsl:attribute>
                 </xsl:if>
                 <xsl:if test="$ItemsHaveStreams != 'True' and @OpenInNewWindow = 'True'">
                   <xsl:attribute name="onclick">
                     <xsl:value-of disable-output-escaping="yes" select="$OnClickTargetAttribute"/>
                   </xsl:attribute>
                 </xsl:if>
                 <xsl:value-of select="$DisplayTitle"/>
             </a>
             <!--<div class="description">-->
                     | <xsl:value-of select="@Description" /> - <xsl:value-of select="@Author" />
             <!--</div>-->
         </div>
     </div>
</xsl:template>

Enjoy

Pierre Vivier-Merle

Posted: vendredi 29 octobre 2010 00:11 par pierre
Ce post vous a plu ? Ajoutez le dans vos favoris pour ne pas perdre de temps à le retrouver le jour où vous en aurez besoin :

Commentaires

Pas de commentaires

Les commentaires anonymes sont désactivés

Les 10 derniers blogs postés

- Merci par Blog de Jérémy Jeanson le 10-01-2019, 20:47

- Office 365: Script PowerShell pour auditer l’usage des Office Groups de votre tenant par Blog Technique de Romelard Fabrice le 04-26-2019, 11:02

- Office 365: Script PowerShell pour auditer l’usage de Microsoft Teams de votre tenant par Blog Technique de Romelard Fabrice le 04-26-2019, 10:39

- Office 365: Script PowerShell pour auditer l’usage de OneDrive for Business de votre tenant par Blog Technique de Romelard Fabrice le 04-25-2019, 15:13

- Office 365: Script PowerShell pour auditer l’usage de SharePoint Online de votre tenant par Blog Technique de Romelard Fabrice le 02-27-2019, 13:39

- Office 365: Script PowerShell pour auditer l’usage d’Exchange Online de votre tenant par Blog Technique de Romelard Fabrice le 02-25-2019, 15:07

- Office 365: Script PowerShell pour auditer le contenu de son Office 365 Stream Portal par Blog Technique de Romelard Fabrice le 02-21-2019, 17:56

- Office 365: Script PowerShell pour auditer le contenu de son Office 365 Video Portal par Blog Technique de Romelard Fabrice le 02-18-2019, 18:56

- Office 365: Script PowerShell pour extraire les Audit Log basés sur des filtres fournis par Blog Technique de Romelard Fabrice le 01-28-2019, 16:13

- SharePoint Online: Script PowerShell pour désactiver l’Option IRM des sites SPO non autorisés par Blog Technique de Romelard Fabrice le 12-14-2018, 13:01