Site Search is an include you can add to your Pages to enable users to search Pages, WebApp items, and Module items for terms they're looking for. By default, this will now search slugs, metadata and Page content.
Site Search now has more configuration options to make searching your site more powerful. This document will cover the new toolbox options for setting up a Site Search. There are two parts of Site Search which you'll need to include in a Site:
Both are available in Toolbox and it is up to you whether you put them on the same Page or different Pages.
If you're using a button to submit your Input Form and there are multiple Input Forms within the same Page there are a couple of attributes you'll need to ensure are added. You'll need to add the button_id parameter to the include for Search Input and this must be unique for each Search Form:
Then add an ID to the button that submits your input, please match this to the ID within the button_id parameter, for example:<button class="btn site_search_submit" id="id_1">Submit</button>
When selecting "Site Search Results" from the toolbox, you have the option of selecting which type of content will be contained within the results. Here you can mix and match whether you would like to display results from Pages, WebApp Detail Pages or Module Detail Pages. For example if you only want to search for Pages on the website then you could have the results exclude any data from WebApps and Modules.
To get results from WebApps or Modules, you must turn on Detail Pages in their configuration in Admin.
If you select WebApps as a Type, you then get a further configuration option to select which WebApps to search. The WebApps dropdown will display all of the available WebApps, this allows you to either select one or multiple WebApps to show results from. If you leave this field empty them the search will show results all WebApps on your Site.
Sometimes you may want to show results from WebApps without detail Pages- perhaps the relevant information is shown in a table instead?
You can add the parameter: allow_list_items: 'true' and WebApp items without Detail Pages will also show in the results.
We strongly recommend that if you use this parameter, you also update your Site Search Results Layout so that it hides links to the Detail Page if one does not exist. You can use the following Liquid if statement to achieve this:
By default, results will appear in a list. You can change the way they display with a custom Layout.
Site Search Module layouts are stored in the following folder structure, which you can view via Code Editor: layouts/modules/site_search/
Within this module folder you will find the following layout folders:
To create a custom layout, right click on the results folder and write a folder, followed by the two required files (item & wrapper).
For example, type: custom_layout_1/wrapper.liquid to create a folder called "custom_layout_1" that contains a file called "wrapper". Right click on your "custom_layout_1" folder to create the final item.liquid file.
Pages, WebApp Items and Module Items may all output different Liquid. This is because they are different sorts of database Objects.
If your search covers more than one type, you may wish to only use output fields which are available to all those types, or you could use if statements to show one field or the other depending on which is available.
For example, if you have a Search Results Layout and you want to display the SEO Meta Title for Pages and WebApps, you can use logic to show whichever one is actually available:
You can also use the default filter: <p>{{this.metadata.title | default: this.properties.meta_title }}</p>
The following output is available for Pages.
This will depend on the WebApp. Use Liquid Dot Notation to see the results for your WebApps. Here is an example of a typical WebApp.
This will depend on the Module. Use Liquid Dot Notation to see the results for your Modules. Here is an example of a typical Module.
You can output the value of any URL parameter using platformOS's context.params object, including the search term in the "keyword" parameter: <p>Search results for: {{context.params.keyword}}</p>
platformOS automatically sanitize tag output to escape any malicious input using the Cross Site Scripting technique.