locked
Search Results Display Templates - conditional statement question RRS feed

  • Question

  • I've got a search results table where it is being populated from two different lists. I'd like to be able to make the results of one of my columns be bold/italic based on which path they came from. I'm not really sure how to accomplish this through my .html file.

     

    The highlighted field is what I'd like this conditional formatting to affect. (_#=.ctx.CurrentItem.Path=#_) - this is the origin of the two different lists. My thought is somehow seeing if the Path contains the word "Private" then it is italics otherwise bold. (Private is in one of the URL's, but not the other). 

    Any help would be appreciated.

    Thursday, November 7, 2019 8:46 PM

Answers

  • Hi,

    Here is my test code.

    if(ctx.CurrentItem.Path.toString().indexOf("ProjectCT")!=-1){
    _#-->
                <div id="_#= $htmlEncode(itemId) =#_" name="Item" data-displaytemplate="DefaultItem" class="ms-srch-item" onmouseover="_#= ctx.currentItem_ShowHoverPanelCallback =#_" onmouseout="_#= ctx.currentItem_HideHoverPanelCallback =#_">
                    _#=ctx.RenderBody(ctx)=#_
                    <b>_#=ctx.CurrentItem.Title=#_</b>
                    <div id="_#= $htmlEncode(hoverId) =#_" class="ms-srch-hover-outerContainer"></div>
                </div>
    <!--#_ 
            } else{_#-->
                <div id="_#= $htmlEncode(itemId) =#_" name="Item" data-displaytemplate="DefaultItem" class="ms-srch-item" onmouseover="_#= ctx.currentItem_ShowHoverPanelCallback =#_" onmouseout="_#= ctx.currentItem_HideHoverPanelCallback =#_">
                    _#=ctx.RenderBody(ctx)=#_
                    _#=ctx.CurrentItem.Title=#_
                    <div id="_#= $htmlEncode(hoverId) =#_" class="ms-srch-hover-outerContainer"></div>
                </div>
    <!--#_         }
    My test result:

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, November 8, 2019 6:30 AM