How to Create a Reusable Custom Style for the Content Query Web Part


By:   |   Updated: 2011-02-03   |   Comments   |   Related: > Sharepoint

Problem

Content Query Web Parts are used to fetch data from different sites in a web application. This web part can be used for various purposes like displaying the latest news or latest events. There can be situations that, despite of having different purposes, the Content Query Web Part might need a uniform data display style.

Solution

The solution is to centralize a style that can be reused.

For our case, we have created two lists: "Movies" and "Shows". These lists will contain basic information like movie or show name, description and their release or event dates.

movies
shows

Next, we have used a multiple Content Query Web Part on a single page to view data from both lists and applied a default presentation style on both.

movies

To create a new custom style, open the site in SharePoint Designer. Go to Style Library -> XSL Style Sheets -> Itemstyle.xsl. "Itemstyle" contains templates that define how to display an item. We have created a very basic custom style named "MyCustomStyle" as shown in the image.

name

After saving the "itemstyle", go to page in a web browser and click edit page. Select the Movies Content Query Web Part and open the tool pane. Go to Presentation -> Styles -> Item Style dropdown.

query

Click on the dropdown and we can see the custom style that we have just defined in itemstyle.xsl.

presentation

Select the style and Click Apply and after that OK.. Now you can see the changes in the Movies Content Query Web Part.

movies

In order to reuse it in the Shows Content Query Web Part, perform the same steps of selecting the style that we have performed on the Movies Content Query Web part.

rain
Next Steps
  • Use Custom Style to define different display styles


Last Updated: 2011-02-03


get scripts

next tip button



About the author
MSSQLTips author Siddharth Mehta Siddharth Mehta is an Associate Manager with Accenture in the Avanade Division focusing on Business Intelligence.

View all my tips





Comments For This Article





download


Recommended Reading

Developer Dashboard in SharePoint 2010

Taking Control of Checked Out Documents in SharePoint

Reading SharePoint Lists with Integration Services 2017

Understanding SharePoint Exports to Excel

Recover a deleted SharePoint site or site collection with the *New* Site Recycle Bin





get free sql tips
agree to terms


Learn more about SQL Server tools