top of page
Writer's pictureKasper Larsen

Using hyperlinks site columns in Search


During a resent PnP Modern Search Office Hours we were looking into how we could surface a Hyperlink site column in the Card layout.



The Hyperlink site column type consists of a display label and an URL.


In order to use it we have to map the crawled property to a managed property, in this case RefinableString140 and 141:



When inspecting the properties in SP Editor it is pretty clear that RefinableString141 contains both the URL and the display label.



In this case I updated the Layout slot for "Tags" to RefinableString141.


Likewise we have to update the Handlebar template for the Tags in Manage Card Fields. The main challenge is split the value in RefinableString141 ( https://www.microsoft.com/, MSFT) into two entities, the URL and the display label, and combine them in a href.

Using "when" and indexing the entities did the trick:

<style>
      .tags {
            display: flex;
            align-items: center;
       }
      .tags i { 
            margin-right: 5px; 
      }
      .tags div {
            display: flex;
            flex-wrap: wrap; 
            justify-content: flex-end; 
      }
      .tags div span {
            text-decoration: underline; 
            margin-right: auto; 
      }
 </style>

{{#if (slot item @root.slots.Tags)}}
      <div class="tags">
            <pnp-icon data-name="Tag" aria-hidden="true" data-theme-variant="{{JSONstringify @root.theme}}"></pnp-icon>
            <div>
                  {{#with (split (slot item @root.slots.Tags) ",") }}
                              <span><a href={{[0]}} style="color:{{@root.theme.semanticColors.link}}">{{[1]}}</a> </span>

                        
                  {{/with}}
            </div>
      </div>
{{/if}}


And voila: the hyperlink is now displayed as a tag in the Card layout:


24 views0 comments

Recent Posts

See All

ESPC 2024

Comments


bottom of page