Wire up home search input to go to search page

This commit is contained in:
Jake Howard 2022-08-04 14:17:50 +01:00
parent 32412c1172
commit 973a50ea9c
Signed by: jake
GPG Key ID: 57AFB45680EDD477
2 changed files with 10 additions and 1 deletions

View File

@ -21,8 +21,13 @@ class HomePage(BasePage):
]
def get_context(self, request: HttpRequest) -> dict:
from website.search.models import SearchPage
context = super().get_context(request)
context["latest_blog_post"] = (
BlogPostPage.objects.live().defer_streamfields().order_by("-date").first()
)
context["search_page"] = (
SearchPage.objects.all().live().defer_streamfields().first()
)
return context

View File

@ -6,7 +6,11 @@
<main {% if page.image %}style="background-image: url({% image_url page.image 'width-1200' %})"{% endif %}>
<div class="heading-wrapper">
<h1>{{ page.heading }}</h1>
<input id="search-input" class="input" type="text" placeholder="Search">
{% if search_page %}
<form action="{% pageurl search_page %}">
<input id="search-input" class="input" type="text" placeholder="Search" name="q">
</form>
{% endif %}
</div>
{% if latest_blog_post %}