Displaying content rating in transformations
The system can also display rating controls in transformations. Place the following code in your transformation, ensuring that the ~/CMSAdminControls/ContentRating/RatingControl.ascx control is displayed along with the transformed item:
<%@ Register Src="~/CMSAdminControls/ContentRating/RatingControl.ascx" TagName="RatingControl" TagPrefix="cms" %>
<cms:RatingControl ID="elemRating" runat="server" Enabled="true" RatingType="Stars" ExternalValue='
<%# Convert.ToString(CMS.Helpers.ValidationHelper.GetDouble(Eval("DocumentRatingValue"), 0)/((CMS.Helpers.ValidationHelper.GetDouble(Eval("DocumentRatings"), 0) == 0?1:CMS.Helpers.ValidationHelper.GetDouble(Eval("DocumentRatings"), 1)))) %>' />
Rating control properties
With this control, you can use similar properties as with the Content rating web part:
Property name |
Property type |
Description |
Enabled |
bool |
Indicates if rating is possible via the control. If disabled, the control is visible but rating is not possible. |
CheckPermissions |
bool |
The same as the Check permissions web part property. |
HideToUnauthorizedUsers |
bool |
The same as the Hide to unauthorized users web part property. |
CheckIfUserRated |
bool |
The same as the Check if user rated web part property. |
AllowForPublic |
bool |
The same as the Anonymous users can rate web part property. |
ErrorMessage |
string |
The same as the Error message web part property. |
MessageAfterRating |
string |
The same as the Message after rating web part property. |
ResultMessage |
string |
The same as the Result message web part property. |
ShowResultMessage |
bool |
The same as the Show result message web part property. |
RatingType |
string |
The same as the Rating type web part property. |
ExternalValue |
string |
Similar as the Rating value property. |
MaxRatingValue |
int |
The same as the Max rating value property. |
Ratings submitted via this control are added to the ratings of the currently displayed page, just as if rated using the Content rating web part.
You can use the content rating and other controls only in transformations of the ASCX type. The rating control is not rendered correctly by other transformation types.
Example - Adding news ratings
The following example demonstrates how you can add the rating control to your pages via transformations. The example uses the sample Corporate site. You will learn how to add the rating functionality to news items displayed in the News section. You can achieve a similar result with the Content rating web part, as described in Using the Content rating web part.
Open the Pages application.
Select the News page in the content tree.
View the page on the Design tab and configure (double-click) the NewsRepeater web part.
In the web part properties dialog, click Edit next to the Selected item transformation property.
Switch the Transformation type to ASCX.
Replace the original transformation with the following code:
<%@ Register Src="~/CMSAdminControls/ContentRating/RatingControl.ascx" TagName="RatingControl" TagPrefix="cms" %> <div class="newsItemDetail"> <h1> <%# Eval("NewsTitle") %></h1> <div class="NewsSummary"> <%# IfEmpty(Eval("NewsTeaser"), "", GetImage("NewsTeaser")) %> <div class="NewsContent"> <div class="Date"> <%# GetDateTime("NewsReleaseDate", "d") %></div> <div class="TextContent"> <%# Eval("NewsSummary") %></div> </div> <div class="Clearer"> </div> </div> <div class="NewsBody"> <div class="TextContent"> <%# Eval("NewsText") %></div> <cms:RatingControl ID="elemRating" runat="server" Enabled="true" RatingType="Stars" ExternalValue=' <%# Convert.ToString(CMS.Helpers.ValidationHelper.GetDouble(Eval("DocumentRatingValue"), 0)/((CMS.Helpers.ValidationHelper.GetDouble(Eval("DocumentRatings"), 0) == 0?1:CMS.Helpers.ValidationHelper.GetDouble(Eval("DocumentRatings"), 1)))) %>' /> </div> </div>
Save the changes.
If you now open the live site, browse to the News section, and display the details of a news item, you can see the rating control is present below the news text.