0

Good day, I have the task to create custom search results page for existing list with thousand elements. The list has Enhanced Rich Text Field “DocFileLink”. The list elements have file links in this field (href html links). And I need to display this field in custom search results. I created new template for element displaying, managed properties. The list elements display correctly, but Enhanced Rich Text creates the problem because the html links convert to anchored text. How can I display Enhanced Rich Text in my custom Search Results template with html links?

My managed property has name “DocFileLinkMP”. Data Type:text

In my custom Search Results template

<mso:ManagedPropertyMapping msdt:dt="string">'Title':'Title',…….,'DocFileLink':'DocFileLinkMP'</mso:ManagedPropertyMapping>

I tried 1.

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

It didn’t help, I see anchored text only in Search Results.

  1. I tried to use script to set html links to search results

    var linkString = ctx.CurrentItem.DocFileLinkMP; if($isEmptyString(linkString) == false) { var attachmentLinks = linkString.split(".pdf"); var numberOfLinks = attachmentLinks.length; var linkMarkup = ""; for(var i=0; i<numberOfLinks; i++) { var fullLink = attachmentLinks[i] + ".pdf"; linkMarkup = linkMarkup + "<a href='/Site/SiteAssets/SitePages/" + fullLink + "'>" + fullLink + "</a>"; } } _#-->

Then

<div class="ms-rtestate-field">
    _#=linkMarkup=#_
</div>

It didn’t help too, because the file can be located in another folder, not in “/Site/SiteAssets/SitePages/”. And link anchored text doesn’t display the file folder, file name only. The link isn’t true for some list elements. I would be pleasure for any ideas.

  • Check this. let me know if it helps you. – Ganesh Sanap Dec 17 '19 at 7:47
  • I created the site column to Publishing HTML (DocFileLinkHTML). Search crawls are running fine. I added a reference to the managed property in the managed property mapping <mso:ManagedPropertyMapping msdt:dt="string">'Title':'Title' ... ,'DocFileLinkHTMLOWSHTML':'DocFileLinkHTMLOWSHTML'></mso:ManagedPropertyMapping> <td class="PageContentColumns" style="width:100px;"> #=ctx.CurrentItem.DocFileLinkHTMLOWSHTML=# </td> It didn't work – Anonymous Dec 18 '19 at 9:15
  • I understood. I created site column (DocFileLinkHTML) on my SubSite and it didn't work. I created site column to Publishing HTML (DocFileLinkHTMLtop) for top-level site, added it to my list. It works fine after full crawling. Thanks for your help. – Anonymous Dec 20 '19 at 9:47
  • Great, glad it worked for you. – Ganesh Sanap Dec 20 '19 at 9:56
1

Try creating a Publishing HTML field at site collection level and then use it in your display template like below:

Add a reference to the managed property(say ArticleContentOWSHTML) in the managed property mapping:

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

and then reference the same in the display template body like:

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

See Rich Text Column content in Display template for Search Results webpart for more information.

| improve this answer | |

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.