divio / aldryn-search

Haystack 2.0 search index for django CMS
Other
48 stars 77 forks source link

How to make search form available in all pages #65

Closed ivanrvpereira closed 8 years ago

ivanrvpereira commented 8 years ago

Hi,

I want to make the search form available on my menu bar, but i cant see how i make this app globally available. Maybe this is a dumb question.

czpython commented 8 years ago

Hello @balsagoth,

I usually create a template tag that renders a template which contains the search form. This encapsulates any logic necessary for the search form to function in a template tag.

Then I use the tag on my base template.

Example:

@inclusion_tag('includes/global_search_form.html')
def render_search_form():
    context = {
        'form': SearchForm()
    }
    return context

The template can be something like:

<form action="{% url "search_form" %}" method="get">
    <input id="field-search" name="q" placeholder="Search" >
 </form>

Because the approach varies a lot from project to project, this is something that Aldryn Search can't provide out of the box.

ivanrvpereira commented 8 years ago

Great @czpython! Thanks for your help.

mateoreyes commented 5 years ago

Hello ! I have these error:

name 'SearchForm' is not defined

can you help me ?