Apply a Conditional IF Statement
When customizing templates in Discovery Search, you may want to display a value only if it exists in the result, so as to avoid displaying empty results.
You can use the following syntax to make a conditional IF statement in your template:
{{#if <value>}}
<!--Your customization here-->
{{/if}}
<value> being:
<value> | Use | Example |
|---|---|---|
| Result template card | result.Document.Source.extension |
| Preview template card | doc.Source.extension |
For example, if you want to display the index value for the field cc-authoring-canvas-content (the field where we store crawled SharePoint page text). You only want to display these customizations if a Discovery Search result has a value for cc-authoring-canvas-content.
Apply this code:
{{#if result.Document.Source.cc-authoring-canvas-content}}
<div class="result-preview text-wrap-row">{{result.Document.Source.cc-authoring-canvas-content}}</div>
{{/if}}