Manage HTML encoding in a Sitecore Single-line text field

Posted 08/02/2016 by Yogeshwer Sharma

Sometime things looks very simple but when we go to actually do them, they become difficult. 

We recently worked on a project and after going live client asked us to manage the Page title (a Single Line Text field) on every page with different colours and other styles.

Firstly we thought it is very simple task we will put HTML elements in Single line text field and Sitecore will automatically manage this while rendering the field value.

We tried this solution and found in case of Single line field it is rendering with HTML tag on website.

For example I entered following html on page title (single line text) field of about us page

<span style=”color:#0088cc;”>Get in touch</span> 

and on front-end it rendered exactly same what we entered in the field as shown in below screenshot.

We started looking for a way to get this HTML tag to render properly. After looking into many blog posts we found that we can manage this by a small config setting change.

Simply add the field type name in which you want to remove HTML encoding in the following config setting:

            Specifies a pipe-separated list of field types that should be HTML encoded when rendered by the  pipeline.
            Default value: text|single-line text
    <setting name="Rendering.HtmlEncodedFieldTypes" value="text|single-line text" />

In our case we have removed “single-line text” from above setting and it started working.

We can find this setting in sitecore.config file under App_Config folder of website root.

Thanks for reading I’ll be keep sharing small fixes to save your time.


Add your comment




  • Yogeshwar Sharma said:
    8/4/2016 1:26 AM

    Thanks Oliver, I am not sure about the solution you provided is out of the box, or need some customization. I'll definitely check it. Also the solution which I provided was quick fix and suitable to our requirement.

  • Oliver said:
    8/4/2016 1:26 AM

    Beware that changing this Config applies the Allow HTML-Setting for EVERY Single-Line Text field on the site! This may lead to unwanted HTML codes being placed where you definitely DONT want Content Authors to do so. Better solution is to create a Config where you can explicitely whitelist fields on specific Templates only, that should allow real HTML Input and rendering.