In this post we will continue the discussion of accessing Social Data in Content Query web part that we started in the previous post. But this time we are going to customize Content Query web part in order to retrieve and display Social Ratings. Our goal here to retrieve and display social ratings using the same way that they are being displayed in List View.
When Ratings is enabled in List settings, the rating field is rendered in List View as shown below
and the customized Content Query web part for displaying Ratings control will look like this
- before we proceed make sure that Social features are configured – a User Profile Service Application is running in the farm. For more information, see Create, edit, or delete a User Profile service application (SharePoint Server 2010)
- Pages Library is used as a data source
So, lets start with the implementation of XSL stylesheet for rendering the Ratings control.
Social Ratings fields in SharePoint 2010
SharePoint 2010 comes with the following fields for Social Ratings:
For rendering AverageRating field in List View the TEMPLATE\LAYOUTS\XSL\fldtypes_ratings.xsl is used. We will utilize templates from this file, but in order to make it work properly with CQWP, some modifications should be applied.
Ratings XSL stylesheet for CQWP
Templates definitions for the client side initialization and for rendering of of Ratings manager
Main XSL stylesheet
Custom ContentQueryMain.xsl is used, in which the template for client side initialization of Ratings control is invoked
Item XSL stylesheet
Custom ItemStyle.xsl is used, in which the template for rendering Ratings control per page is invoked
Ratings XSL Parameters
Parameter values are retrieved from resource file and are passed via ParamaterBindings web part property
In order to configure CQWP for displaying Social Ratings , the following steps should be accomplished:
- upload XSL stylesheets RatingsStyle.xsl, ItemStyle_Ratings.xsl and ContentQueryMain_Ratings.xsl into Style Library
- specify MainXslLink, ItemXslLink and ParamaterBindings web part properties
- How to: Create and Retrieve a Social Rating
- How to: Customize XSL for the SharePoint Content By Query Web Part (ECM)