I am trying to set up a search form in my website. Followed this tutorial on builtwithcraft documentation website.

So in my top navigation bar I include this code

<form class="navbar-form navbar-right" role="search" action="{{ url('/oeuvres/_results') }}">
    <div class="input-group">
        <input type="search" class="form-control" name="q" placeholder="Recherche">
        <span class="input-group-btn">
            <button type="button" class="btn btn-default" value="Go"><span class="glyphicon glyphicon-search"> </span></button>

And then the result page:

{% extends "_layout" %}

{% block main %}
    {% include "includes/_topNav" %}

    <div class="container">
        <div class="row">
            <div class="col-md-12">

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

                {% if entries|length %}
                    <p>{{ entries|length }} Votre recherche:</p>
                        {% for entry in entries %}
                            <li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
                        {% endfor %}
                {% else %}
                    <p>Votre recherche “{{ query }}” n'a donné aucun résultat.</p>
                {% endif %}

    {% include "includes/_javaScript" %}
{% endblock %}

I have no idea what is wrong, it seems that the "q" param is passing through the result page (the address line is for example: http://www.example.com/oeuvres/_results?q=routes But the page is totally blank. Meaning nothing gets generated between the body tags. (not even the template tags...

I can't find what I am missing here.


Templates starting with an underscore character is by default denied direct access in Craft (resulting in a 404 not found error). I guess that renaming your template to "results" should fix it.

  • that was it! Thanks. Strange enough, my 404 template is not showing up at all...
    – jjem
    Sep 22 '14 at 12:06
  • Check that you don't have any rewrite rules in your .htaccess concerning 404 handling. If there is a redirect in there, the request doesn't reach Craft at all. Sep 22 '14 at 12:42

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.