Showing managed metadata tag names in PnP Modern Search result templates

When retrieving a mapped managed metadata value from a search result, you might get the following back:

"RefinableString100": "GP0|#f1527ba5-5934-44f9-85d2-bb05dde6630a;L0|#f77cc337-58b0-4791-b4c8-6d38f8882718|Sample term;GTSet|#f8c2158b-6890-4f8a-b016-c73676672638",

To get just the value Sample term, we can split it and loop through the values. If one starts with L0, we can use getTagName to get the text. This works with multiple tags too. It outputs (None) if there are no values.

{{#if item.RefinableString100}}
  <ul>
    {{#each (split item.RefinableString100 ';') as |tag|}}
      {{#startsWith 'L0' tag}}
        <li>{{getTagName tag}}</li>
      {{/startsWith}}
    {{/each}}
  </ul>
{{else}}
  <span>(None)</span>
{{/if}}

Related posts