How to render links in search results
murphym215 opened this issue · 1 comments
Category
- [X ] Question
- Bug
- [] Enhancement
Expected or Desired Behavior
I need some guidance/help with links in search results.
I have a SharePoint list with a few enhanced rich text multi-line text fields, some contain links to documents in a document library, some contain links to external websites. When adding a link to these fields, I am asked to enter two things, Text to Display and Address, which is the url (see image below). The links work fine from within the list, but I need to render them in a custom search results template.
I have mapped these columns to RefinableStrings and have tried creating a new managed property and mapping to it.
In the search results, I want to be able to click on those links, however, only the 'display text' portion of the link entry is being returned. How do I get the url portion? I've tried several handlebar helpers (JSON Stringify, Url, getUrl), but all I keep getting is the display text.
Is there a specific handlebar helper i should be using for this? Is it even possible? Any help would be greatly appreciated, I've spent numerous hours trying to figure this out.
If you use a URL site column, both the title and URL are retrievable. From within the text itself, they are not, as only text is indexed - not the entire markup.
See the implementation for this in the pnp modern search web parts:
https://github.com/microsoft-search/pnp-modern-search/blob/b9c9d82082e64a145c1a4b2fb26199625e9f5e67/search-parts/src/services/TemplateService/BaseTemplateService.tsx#L250
But it has to a site column, not a list/library column due to depending on the automatic managed property.