top of page

Using hyperlinks site columns in Search

  • Writer: Kasper Larsen
    Kasper Larsen
  • Jun 18, 2024
  • 1 min read

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


ree

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:

ree


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

ree


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

ree

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:

ree

 
 
 

Comments


30103817

  • Twitter
  • LinkedIn

©2023 by M365thinking. Proudly created with Wix.com

bottom of page