Introduction
Using social comments in Publishing pages is pretty common scenario for SharePoint Publishing Sites. In comparison to page fields (Page Content, Title, Page Image and etc.) that are inserted into the “slots” of the page layout and associated with the content type of the publishing page, social comments are stored separately. Social comments are stored in separate DB and the comment entry is associated by the page Url on which comment has been given.
Let’s take a look at several approaches how to display social comments for Publishing pages in Content Query web part as shown on picture below.
Prerequisites: to enable social comments in Publishing pages the custom page layout with Note Board web part is used for demonstration here.
Extending Content By Query web part
In this approach the social comments are retrieved and saved in results before it is sent to the XSL transform using ProcessDataDelegate delegate of Content Query web part. For retrieving social comments, SocialCommentManager class is utilized, which represents the entry point in SharePoint object model (OM) that exposes methods to do work with social comments or notes.
So, in order to attach method for processing of social comments to a delegate ProcessDataDelegate we need to subclass Content Query web part as demonstrated below:
And the final step is to customize template for rendering item (ItemStyle.xsl) in order to render social columns (comment count per page in our case) in Content Query web part:
<div class="comments"> | |
Comments: <span class="comments" pageurl="{@PageUrl}"><xsl:value-of select="@PageComments" /></span> | |
</div> |
Utilizing SharePoint Web Services for retrieving social comment in CQWP
In this approach we are not going to subclass Content Query web part, but implement social comments retrieving and binding on the client side.
SharePoint Web Services exposes Social Data Service that provides methods for remote clients to Create, Read, Update, and Delete (CRUD) social data.
The following JavaScript code demonstrates how to utilize SharePoint Web Services for retrieving comment count per page and to bind it to comments item template (ItemStyle.xsl)
Code excerpt for comment item from ItemStyle.xsl:
<div class="comments"> | |
Comments: <span class="comments" pageurl="{@LinkUrl}"></span> | |
</div> |