Blog

How to Customize your libraries using a Content Query Web Part and Folders in SharePoint.

You can use the out of the box Content Query Web Part, to control how the content is displayed for everything contained on libraries and lists.

These simple steps will help you customize the main view of your library

  1.  Create your library using folders (this will help us organize the items), and go to the main view (i.e. AllItems.aspx)

2.     Go to Site Actions, Edit Page, and add the Content Query Web Part (CQWP) to your page.

 

3.    By default the CQWP will display all of the pages in the site.   

4.     Click on edit menu, then choose to Modify the Shared Web Part and in the Web Part Tool Pane, expand Query and change the Source settings to the library where you want to apply the display change. Also choose “Document Library” from the List Type drop down.

        5.     When you finish this step, click OK and Exit Edit Mode.

        6.     We can start modifying the styles for the CQWP. Open your site with SharePoint designer, and look for the Style Library. Open the XSL Style Sheets folder, and then the ItemStyle.xsl file.

        7.       Every time you see "<xsl:template..." it is the start of a new Item Style.  There is one for each of the out-of-the-box Item Styles that show up in the Styles drop down in the Web Part Tool Pane.  For every custom Item Style that is needed, a new xsl:template block will have to be created. So, in this case, we will create a new template:


       <xsl:template name="MyCustomStyle" match="

        Row[@Style='MyCustomStyle']"

        mode="itemstyle">

              <!-- Variable declarations -->

<!-- HTML Structure -->       </xsl:template>

 

             8.       The fields that we need are: the title of the item, and the URL. We can create two variables to build our structure easily (<!-- Variable declarations -->).


 <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>

 

         9.      Then we use the variables on our html structure (<!-- HTML Structure -->), like this:

 <div class="itemsAsterisk">

            <img src="../../SiteCollectionImages/asterisk.png" />

            <a href="{$SafeLinkUrl}">

                <xsl:value-of select="$DisplayTitle" />

            </a>

        </div>

In this case I’m using an asterisk image, but this can be replaced for a different tag, or removed.

 

 

      10.        Our item style is ready, now save and publish the ItemStyle.xsl file.

 

        11.        Go to your Library main page, Edit Page, edit (web part menu) and on the Web Part Tool Pane and expand Presentation. Select your brand new item style from the drop down, and click OK to apply the changes.

         12.       Your CQWP now looks like the image below:

       13.     Now you can delete the old list view clicking edit (web part menu), Delete.

And that's it, we are done customizing your libraries. Piece of cake!

 

Comments

Leave a comment

 
 
 
 
CAPTCHA Image Validation