Dot All Lisbon – the official Craft CMS conference – is happening September 23 - 25.

Search Form

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

  <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:


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

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

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