12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on Oct 4, 2019

[Condition] At Least 1 Search Result

Sridhar Katakam

This members-only tutorial provides the steps to register a custom condition to be applied on elements inside an Oxygen Template that applies to search results.

The condition lets us conditionally output elements depending on whether there is at least one search result or not.

Use Case

This condition can be used in conjunction with the How to create a Search Results page in Oxygen tutorial so that a message can be shown when there are 0 search results.

When there's at least 1 search result:

When there's no search results:

To set this up, you would move everything inside the Template for search results from the other tutorial inside a Div and set this condition on that Div:

After that you would create another Div alongside (at the same level as) the earlier Div and add Heading/Text/Search Form telling the user that there are no results for the term they searched for. Then you'd apply the condition on this Div like so:

Step 1

Install and activate Code Snippets plugin.

Go to Snippets > Add New.

Title: [Condition] At Least 1 Search Result

Code:

This is a premium members-only content.

To view the rest of the content, please sign up for membership ($47/month or $599 one-time).

Already a member? Log in below or here.

tagschevron-leftchevron-rightchainangle-rightangle-upangle-downfolder-omagnifiercrossmenuchevron-downarrow-right