search

You can use the search variable with the following templates: search.liquid.

The liquid variable search has the following attributes:

search.performed
{% if search.performed %}
  {{ search.results }}
{% endif %}

Returns "true" if search terms were entered in the search box.

search.results
{% for item in search.results %}      
<li class="clearfix">
  <h3>{{ item.title | link_to: item.url }}</h3>
  {% if item.featured_image %}
  <div class="result-image">
    <a href="{{ item.url }}" title="{{ item.title | escape }}">
      {{ item.featured_image.src | product_img_url: 'small' | img_tag: item.featured_image.alt }}
    </a>
  </div>
  {% endif %}
  <span>{{ item.content | strip_html | truncatewords: 40 | highlight: search.terms }}</span>        
</li>
{% endfor %}

Returns a list of any matches found within the store's product pages and content pages. You can loop through each item in the search.items list.

search.results_count
{% if search.results.size > 0 %}
  {{ search.results_count }}{{ search.results_count | pluralize: 'result', 'results' }}
{% endif %}

Returns the number of results found.

search.terms
<span>{{ item.content | strip_html | truncatewords: 40 | highlight: search.terms }}</span>

Returns the string that was entered in the search input box.

Ready to put what you've learned into action?

Build an online store with Shopify Try it Free

Experience the future of retail now

Shopify Point of Sale Try it Free