search
The search template handles the rendering of the search results page, displaying products and content that match a customer's query.
Location
The search template is located in the templates directory of the theme.
bash
└── theme
├── layout
├── templates
│ ...
│ ├── search.json
│ ...
...Usage
The search template receives no data object. Results are fetched by paginating the special search.products collection, which reads the query string of the /search request (q, sort_field, sort_order, filters[]).
liquid
{% paginate search.products by 24 cod %}
<p>{{ total }} results for "{{ terms }}"</p>
{% for product in items %}
<!-- product info -->
{% endfor %}
{% endpaginate %}items holds the matching product objects for the current page. See the paginate tag for the other variables exposed inside the block (total, current, next_page, and so on).
terms is exclusive to search.products — it holds the submitted search query (?q=).
Search form
The search form only needs to GET /search with a q input:
liquid
<form action="/search">
<input name="q" type="text">
</form>