site_search
This component outputs data relating to a site search request passed in a URL parameter SearchKeyword
to any page (typically from a search form submission).
{% component type: "site_search", source: "Page", layout: "Site Search List" %}
Search queries are currently made against all of the following modules:
- Pages
- Blogs (Blogs and Posts)
- Events (Groups and Items)
- Banners (Groups and Items)
- Galleries/Sliders (Groups and Items)
- FAQs (Groups and Items)
- Custom Modules
- Authors
- Products/Catalogs
Parameters and Options
site_search
This is the name of the entity that needs to be used for the component retrieving function.
Page (default)
<Entity name/ID>
Site Search List (default)
<Your Layout name>
The layout name you want to use for rendering the component. The layout name is referenced from the available Layouts of the source specified.
While this parameter is required to render your Layout markup, if the parameter is blank, has an incorrectly referenced Layout, or is removed altogether then the component will still output the modules item data to a Liquid collection which can be accessed via the collectionVariable
parameter.
id
parentid
name
weighting
url
urlslug
releasedate
expirydate
LastUpdatedDate
Author
ItemCategories
ItemTags
<CustomPropertyName>
...and any other top level properties available for the module
Remove spaces from custom property names here.
ASC (default)
DESC
ASC
sorts the items in ascending order while DESC
sorts in descending order (based on alpha/numeric or date sorting).If empty or not present, alpha/numeric sorting will be used.
false (default)
true
false
items will sort by their weighting values first, followed by any sortBy properties (or the default alpha/numeric sorting if sortBy is empty or not present). If true
item weightings will be ignored and sorting will only be applied via sortBy or default sorting.false (default)
true
If used in conjunction with sortOrder the sorting criteria will be applied to the randomly retrieved results.
10 (default)
<integer>
true (default)
false
This is useful for avoiding pagniation affects for a specific component when multiple components of the same module are output on the same page and do use pagination.
false (default)
true
<Your custom message>
SearchKeyword
parameter (not if no search results are found). The default is no content.Liquid variables are supported here, although Liquid logic tags and HTML are not.
If using Liquid variables with filters added, be sure to change any double quotes to single quotes. For eg: emptyMessage: “{{ myVariable | prepend: 'Error: ' }}”
To use HTML in your empty message, first capture it using a Liquid capture, then insert the capture variable into the emptyMessage parameter.
item (default)
collection
item
returns each item iteratively, one after another, for output (generally, output to a container element with no need for looping through the data).collection
returns all items as one collection for output (your container element and looping logic would be handled in the Components Layout).<yourLiquidVariableName>
Your collectionVariable value must only contain English letters, numbers or underscores. Spaces or special characters are not supported.
<your custom value>
Your <customParameter> name must only contain English letters, numbers or underscores. Spaces or special characters are not supported.
You can use HTML as the value here, just be sure to change any double quotes in your HTML to single quotes.
Also, see here for a tutorial on using Custom Paramters.
Liquid Output
For an example of the Liquid data that will be output from this components, please see the ‘Basic Site Search Demo’ link in the External Resources section below.
Accessing the Data
JSON Output
You can output the full JSON for your component data by referencing the root Liquid object {{this}}
in your module’s layouts, or directly on your page, if using the collectionVariable
parameter in your component tag.
For example:
{% component type: ... collectionVariable: "myData" %}
You can then render the JSON like so:
{{myData}}
For more details on using this approach, see Part 2 of the free ‘Learning Liquid Course’.
Rendering Property Values
This data is accessible in two main ways:
1. Using Liquid in the specified Layout via the this
object.
{{this['name']}}
2. Directly on the Page or Template via a Liquid Collection if collectionVariable
was added to the Component tag.
An example using collectionVariable
with value "searchResults" is as follows:
{% component type: "site_search", source: "Page", layout: "", collectionVariable: "searchResults" %}
Looping through the collection to render all the item names in a list:
<ul>
{% for sr in searchResults.items %}
<li>{{sr['name']}}</li>
{% endfor %}
</ul>
Accessing a specific item within the collection. In this case the first item name (zero based index):
{{searchResults.items[0]['name']}}
Related Articles
- Content Modules
Site Search
Site search allows general searching of all module items throughout the entire site.
External Resources
Please let us know if you have any other contributions or know of any helpful resources you'd like to see added here.
Questions?
We are always happy to help with any questions you may have.
Visit the Treepl Forum for community support and to search previously asked questions or send us a message at support@treepl.co and we will consult you as soon as possible.