I've created a custom Sharepoint Search Result page using a list template, and I've added a line at the bottom of each result that shows Category: URL

The URL is obtained from a custom column that is a managed property, which I've added into my Slots layout. Not every result will have a URL listed in the custom column. In those instances it shows Category: and then a blank space. What I would like to do is completely hide the category line, if the result has no value in the column.

I tried using the following:

{{#if @root.slots.CategoryURL}}
<div><b>Category: </b><a href="{{slot item @root.slots.CategoryURL}}"><i>{{slot item @root.slots.Summary}}</i></a></div>

but all results still show the category line.

I also tried:

{{#if @root.slots.CategoryURL !=""}}
<div><b>Category: </b><a href="{{slot item @root.slots.CategoryURL}}"><i>{{slot item @root.slots.Summary}}</i></a></div>

but this causes the web part to not display any results anymore.

How can I hide this line based on whether the column has data for that particular returned search result item?

  • Can you try using: {{#if slot item @root.slots.CategoryURL}} <div><b>Category: </b><a href="{{slot item @root.slots.CategoryURL}}"><i>{{slot item @root.slots.Summary}}</i></a></div> {{/if}} Mar 9 at 7:50
  • Let me know if this works for you. If not I can help you with custom handler. Mar 9 at 8:07
  • This still causes the web part not to display any results
    – Ronnie
    Mar 9 at 13:56
  • Can you try using custom handlebar(isdefined) like shown here: handlebarsjs.com/guide/builtin-helpers.html#sub-expressions Mar 9 at 13:59
  • I tried {{#if (isdefined slot item @root.slots.CategoryURL)}} <div><b>Category: </b><a href="{{slot item @root.slots.CategoryURL}}"><i>{{slot item @root.slots.Summary}}</i></a></div> {{/if}} but this also gave no results
    – Ronnie
    Mar 9 at 14:09


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.