I am building a display template for a CSWP. One of the properties is a multi-lined textbox and some HTML is stored with the actual data. How do I go about rendering this html in my display template?

Sample Data

<div class="ExternalClassAE8F3DF56FC4439E9AA218A73E8A5409">
    ​    <span style="color&#58;#000000;font-family&#58;arial, helvetica, sans;font-size&#58;11px;
line-height&#58;14px;text-align&#58;justify;">Lorem ipsum dolor sit amet, consectetur adipiscing 
elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, 
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute 
irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. 
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id 
est laborum.
  • Currently how is it getting rendered? With HTML formatting or without? Jan 19 '15 at 22:30
  • Plain text. No HTML formatting Jan 19 '15 at 22:52
  • ExceptionLimeCat - You mean you don't want any HTML formatting to be applied to the result? Jan 19 '15 at 22:53

You can use following code in the display template

<div title="_#= $htmlEncode(line4.defaultValueRenderer(line4)) =#_" id="_#= line4Id =#_">

Source - https://ingessharepointnotes.wordpress.com/2014/03/04/sharepoint-display-templates-display-enhanced-rich-text-field/

Another example

var desc = $getItemValue(ctx, "Description");
_#= STSHtmlDecode(desc.value) =#_

Source - http://rwcchen.blogspot.com/2013/06/sharepoint-2013-working-with-display.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.