Quick Tip: Render Rich Text as HTML in your SharePoint 2013 Display Template

In your SharePoint display template this is where you add in the fields you want to capture the values of
<mso:ManagedPropertyMapping msdt:dt=”string”>…</mso:ManagedPropertyMapping>

using this syntax
property name‘{property display name}:’managed property’

  • property name
    is what you use in the script area to capture the value and store it in a variable
  • property display name
    is the property name that shows in the Web Part editing pane
  • managed property
    is the managed property you want to get the value of

like so…

<mso:ManagedPropertyMapping msdt:dt="string">'desc'{Description Label}:'Description'</mso:ManagedPropertyMapping>

you will use the property name in your code to capture the value of that field and store in a variable

var description = $getItemValue(ctx, "desc");

if you were to just render the value of the variable like this

_#= description =#_

you would just get all the HTML characters as text

to not have all the HTML markup render as text, use this syntax

 _#= STSHtmlDecode(description.value) =#_ 


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

5 × 1 =