Question

I am trying to display content from a rich text column (ArticleContent) in my search results webpart using a custom display template.

<div id="_#= $htmlEncode(itemId) =#_" name="Item" data-displaytemplate="DefaultItem" class="ms-srch-item">
            <table>
                <tr>
                    <td class=”PageContentTitle”>
                    _#=ctx.CurrentItem.Title=#_                     
                    </td>
                </tr>
                <tr>
                    <td class=”PageContentColumns”>
                     _#=ctx.CurrentItem.ArticleContent=#_
                    </td>
                </tr>
            </table>
            <div id="_#= $htmlEncode(hoverId) =#_" class="ms-srch-hover-outerContainer"></div>
 </div>

The Title and any other single line of text or number column is displaying fine, but when I am use a rich text column, the result is plain text. So in order to maintain formatting I changed the site column to Publishing HTML (Page Content) but now the content is always blank. Any ideas?

Update: Search crawls are running fine. I have also run a full crawl to be sure.

Was it helpful?

Solution

I found the solution finally, I was mapping to the column field itself (ArticleContent) which was not providing any results. What I did not notice was that Sharepoint Search created a managed property for the Publishing HTML field (ArticleContentOWSHTML) which was now available.

I added a reference to the managed property in the managed property mapping

<mso:ManagedPropertyMapping msdt:dt="string">'Title':'Title' ... ,'ArticleContentOWSHTML':'ArticleContentOWSHTML'></mso:ManagedPropertyMapping>

and referenced the same in the display template body

<tr>
   <td class=”PageContentColumns”>
    _#=ctx.CurrentItem.ArticleContentOWSHTML=#_
   </td>
</tr>

Now Rich text content is flowing into the search results without issues!

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top