Skip to main content
Skip table of contents

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:

CODE
{{#if <value>}}
  <!--Your customization here-->
{{/if}}

<value> being:

<value>

Use

Example

result.Document.Source.<field_name>

Result template card

result.Document.Source.extension

doc.Source.<field_name>

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: 

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}}
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.