How to Create a Reusable Custom Style for the Content Query Web Part
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.
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.
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.
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.
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.
Click on the dropdown and we can see the custom style that we have just defined in itemstyle.xsl.
Select the style and Click Apply and after that OK.. Now you can see the changes in the Movies Content Query Web Part.
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.
- Use Custom Style to define different display styles
About the author
View all my tips
Article Last Updated: 2011-02-03