Adding site search to a site template/page and redirecting the results

  1. Go to template or page where search needs to be inserted

  2. Go to Components and select Site Search

  3. It will say code is copied. This is what the code will look like:
    site-search-code
    {% component source: “Page”, layout: “Site Search List”, displayPagination: “true”, type: “site_search” %}

  4. Paste the code into the div where you want the site search to be.

  5. You can redirect to a page where the search results are shown by changing to
    ie. The name of the page you want the search result to show on.

If you do that you need to put the search results code on the search results page, and remove it from under the search form.

{% component source: “Page”, layout: “Site Search List”, displayPagination: “true”, type: “site_search” %}

  1. So the full code is now:

IN TEMPLATE/PAGE WHERE SEARCH BAR NEEDS TO BE:
site-search-code2

ON SEARCH RESULT PAGE eg: /search-page.htm
{% component source: “Page”, layout: “Site Search List”, displayPagination: “true”, type: “site_search” %}

NOTE: Search results will paginate automatically with this code.

More documentation here: https://docs.treepl.co/documentation_group/component-types/site_search
Liquid Components > Site Search

When there are no results found nothing is displayed. How do we have “No Results Found” display when there are no results?

Hi @cretam
You can add the emptyMessage parameter to the component tag, ie:

{% component source: "Page", layout: "Site Search List", emptyMessage: "No items found", displayPagination: "true", type: "site_search" %}

You can even add Liquid to this to display dynamic content, like the keyword searched for example:

{% component source: "Page", layout: "Site Search List", emptyMessage: "No items found by keyword: <strong>{{request.request_url.params.SearchKeyword}}</strong>", displayPagination: "true", type: "site_search" %}

Thanks Adam. It works ok for words that are not on the site. I tried “business of sheep” and got a funny one - Showing 18 items for “business of sheep

Sorry no results found. Try searching again with a different keyword perhaps.
This listed multiple times. Would you mind checking if it is working correctly on my site https://www.sheepconnectsa.com.au/ please?

This is because your Site Search List layout is set up to render items as a ‘collection’.
So you need to add object: "collection" to the search component, ie:

{% component source: "Page", layout: "Site Search List", object: "collection", emptyMessage: "No items found by keyword: <strong>{{request.request_url.params.SearchKeyword}}</strong>", displayPagination: "true", type: "site_search" %}

Thanks Adam. That fixed it.