---
title: Displaying content rating in transformations
related:
  - https://docs.kentico.com/k8/developing-websites/loading-and-displaying-data-on-websites/writing-transformations.md
  - https://docs.kentico.com/k8/community-features/content-rating/using-the-content-rating-web-part.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

Rating controls can also be displayed in [transformations](https://docs.kentico.com/k8/developing-websites/loading-and-displaying-data-on-websites/writing-transformations.md). Place the following code in your transformation, ensuring that the _**\~/CMSAdminControls/ContentRating/RatingControl.ascx**_ control is displayed along with the transformed item:

```html

<%@ 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)))) %>' />

```

With this control, you can use similar properties as with the Content rating web part, as described in [Using the Content rating web part](https://docs.kentico.com/k8/community-features/content-rating/using-the-content-rating-web-part.md):

- **bool Enabled** - indicates if rating is possible via the control. If disabled, the control is visible, but rating is not possible.
- **bool CheckPermissions** - the same as the Check permissions web part property.
- **bool HideToUnauthorizedUsers** - the same as the Hide to unauthorized users web part property.
- **bool CheckIfUserRated** - the same as the Check if user rated web part property.
- **bool AllowForPublic** - the same as the Anonymous users can rate web part property.
- **string ErrorMessage** - the same as the Error message web part property.
- **string MessageAfterRating** - the same as the Message after rating web part property.
- **string ResultMessage** - the same as the Result message web part property.
- **bool ShowResultMessage** - the same as the Show result message web part property.
- **string RatingType** - the same as the Rating type web part property.
- **string ExternalValue** - similar as the Rating value property.
- **bool AllowZeroValue** - the same as the Allow zero value property.
- **int MaxRatingValue** - the same as the Max rating value property.

Ratings submitted via this control are added to the ratings of the currently displayed document, the same as if you rated via the Content rating web part.

> **Note:** You can use the content rating and other controls only in transformations of type **ASCX**. The rating control will not be rendered correctly by other transformation types.

## Example - Adding news ratings

The following example demonstrates how to add the rating control to your pages via transformations. We will use the sample Corporate Site and add the rating functionality to news items displayed in the News section. A similar result can be achieved using the Content rating web part, as described in [Using the Content rating web part](https://docs.kentico.com/k8/community-features/content-rating/using-the-content-rating-web-part.md).

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:

   ```html

   <%@ 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.

Now if you go to the live site, browse to the **News** section and display the details of a news item, you see the rating control present below the news text\*\*\*.\*\*\*
