Search Form

This document is for a version of Craft CMS that is no longer supported. Please refer to the latest version →

To create a search form, first create a normal HTML form with a ‘search’ input:

<form action="{{ url('search/results') }}">
  <input type="search" name="q" placeholder="Search">
  <input type="submit" value="Go">

Then, on whatever template your form submits to (e.g. search/results.html), just pull the search query from the GET/POST data, and pass it to the “search” param on craft.entries:

<h1>Search Results</h1>

{% set query = craft.request.getParam('q') %}
{% set entries ='score') %}

{% if entries|length %}
  <p>{{ entries|length }} results:</p>

    {% for entry in entries %}
      <li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
    {% endfor %}
{% else %}
  <p>Your search for “{{ query }}” didn’t return any results.</p>
{% endif %}