When you click in search form and press 'Enter' or 'Submit' button, it returns all entries, that exist in database.

How could I display some message rather than all entries?

1 Answer 1


You could use a conditional to check if your "search term" parameter has a value.

<h1>Search Results</h1>

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

{% if query|length  %}

    {% set entries = craft.entries.search(query).order('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 %}

{% else %}
    <p>You forgot to enter a search term.</p>
{% endif %}

(This code is modified from the examples in the Craft docs for "Search Form")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.