1

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?

2

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>

        <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 %}


{% 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, privacy policy and cookie policy

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