---
title: Displaying content rating in transformations
related:
  - https://docs.kentico.com/k11/developing-websites/loading-and-displaying-data-on-websites/writing-transformations.md
  - https://docs.kentico.com/k11/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).

The system can also display rating controls in [transformations](https://docs.kentico.com/k11/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)))) %>' />

```

## 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.

> **Note:** 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](https://docs.kentico.com/k11/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, add _DocumentRatings_ and _DocumentRatingValue_ columns to the **Columns** field in the **Content filter** category.
5. In the web part properties dialog, click **Edit** next to the **Selected item transformation** property in the **Transformations** category.
6. Switch the **Transformation type** to _ASCX._
7. 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>

   ```
8. 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\*\*\*.\*\*\*
