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 nameProperty typeDescription

Enabled

boolIndicates if rating is possible via the control. If disabled, the control is visible but rating is not possible.
CheckPermissionsboolThe same as the Check permissions web part property.
HideToUnauthorizedUsersboolThe same as the Hide to unauthorized users web part property.
CheckIfUserRatedboolThe same as the Check if user rated web part property.
AllowForPublicboolThe same as the Anonymous users can rate web part property.
ErrorMessagestringThe same as the Error message web part property.
MessageAfterRatingstringThe same as the Message after rating web part property.
ResultMessagestringThe same as the Result message web part property.
ShowResultMessageboolThe same as the Show result message web part property.
RatingTypestringThe same as the Rating type web part property.
ExternalValuestringSimilar as the Rating value property.
MaxRatingValueintThe 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.

  1. Open the Pages application.
  2. Select the News page in the content tree.
  3. View the page on the Design tab and configure (double-click) the NewsRepeater web part.
  4. In the web part properties dialog, click Edit next to the Selected item transformation property.

  5. Switch the Transformation type to ASCX.

  6. 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">&nbsp;</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>
  7. 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.


Was this page helpful?