I have a Content Search Web Part (CSWP) that lists two different content-types from a different application.

I would really like to be able to make the CSWP show content-type A in green and content-type B in red.

I tried to look at creating a display template for it, but I can't seem to crack the necessary JavaScript code.

Have anyone tried this setup or know how to set it up?



Yes we can achieve this using display templates.

First if you are using an OOB display template, I would suggest make a copy of it in and customize it based on your requirement.

Now as you have a hold of a custom display template, Make sure you map ContentType field in ManagedPropertyMapping

something like below in your display template

'Line 2'{Line 2}:'ContentType'

Now in the html section you just need to check content type value and give css to the div or any element which populates content type name

if(line2 == "ContentTypeA")
            <div class="ms-noWrap" style="background-color:green">_#= line2 =#_</div>
}else if(line2 == "ContentTypeB"){
            <div class="ms-noWrap" style="background-color:red">_#= line2 =#_</div>


I hope this helps :)

  • No Problem.. Happy to help :) – Asad Refai Apr 29 '15 at 9:00

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.