Change log

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

Parameter
Values
Required
Description
type
site_search

This is the name of the entity that needs to be used for the component retrieving function.

source
Page (default)
<Entity name/ID>
The entity name or ID that the layout is to be referenced from.
layout
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.

sortBy
id
parentid
name
weighting
url
urlslug
releasedate
expirydate
LastUpdatedDate
Author
ItemCategories
ItemTags
<CustomPropertyName>
...and any other top level properties available for the module

The name of the property to sort by. If empty or not present, alpha/numeric sorting will be used.

Remove spaces from custom property names here.

sortOrder
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.
ignoreWeighting
false (default)
true

Enables/disables sorting items first by their weighting values. When 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.
random
false (default)
true

Retrieves matched search results at random. For example, if you limit the results to 5 but 10 items are matched to the search term, 5 of the 10 results will be output at random. If pagination applied, th esecond page will be the 5 remaining random items.

If used in conjunction with sortOrder the sorting criteria will be applied to the randomly retrieved results.

limit
10 (default)
<integer>

The maximum number of items returned. If displayPagination is enabled this determines the maximum number of items per page.
enablePagination
true (default)
false

Enables/disables pagination for the component.

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.

displayPagination
false (default)
true

Displays pagination if there are more items available than the limit set.
emptyMessage
<Your custom message>

Custom content that is rendered if no value is passed to the 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.

object
item (default)
collection

Determines the method for Liquid rendering.
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).
collectionVariable
<yourLiquidVariableName>

Assigns the data to a Liquid collection enabling further access to the data on the Page or Template using Liquid.

Your collectionVariable value must only contain English letters, numbers or underscores. Spaces or special characters are not supported.

<customParameter>
<your custom value>

You can add your own additional parameters (name/value pairs) to the Component tag. These will be passed to the Components Layout (and the collectionVariable if used) for use via Liquid.

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.