Created
January 27, 2017 21:37
-
-
Save davidhellmann/bcff756336391e0ad3173a3ceba34511 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends craft.request.isAjax ? 'layout/_ajaxLayout' : 'layout/_layout' %} | |
{% block content %} | |
{% set keywords = craft.request.getParam('query')|split('/') ?: false %} | |
{% set searchParam = keywords|join(' OR ') %} | |
{% set criteria = { | |
collections: ['bodies', 'entries'], | |
params: { | |
limit: 14, | |
keywords: searchParam | |
} | |
} %} | |
{% if craft.request.isAjax %} | |
{% amSearchPaginate criteria as searchResults %} | |
{%- autoescape 'js' -%} | |
{{ searchResults|json_encode|raw }} | |
{%- endautoescape -%} | |
{% else %} | |
<section class="l-section c-content"> | |
<div class="l-container"> | |
<h1 class="c-headline c-headline--featured"> | |
Deine Suche | |
</h1> | |
<div class="c-search"> | |
<div class="v-search c-input"> | |
<form action="{{ url('search') }}"> | |
<input type="search" | |
name="q" | |
placeholder="Suchen..." | |
class="c-input__field" | |
value="{{ craft.request.getParam('q') }}" | |
> | |
</form> | |
</div> | |
</div> | |
<h1 class="c-headline--featured">Suchergebnisse</h1> | |
{% amSearchPaginate criteria as searchResults %} | |
{# Search results #} | |
{% if not searchResults|length %} | |
<p>{{ 'There are no search results.' }}</p> | |
{% else %} | |
{% for searchResult in searchResults %} | |
{% set entry = craft.entries.id(searchResult.id).first() %} | |
{% if entry.contentBuilder_sections|length %} | |
{% set excerpt = entry.contentBuilder_sections.level(2).type('copy').first().body|split('</p>') %} | |
{% endif %} | |
{% if excerpt is of_type('array') %} | |
{% set excerpt = excerpt|first %} | |
{% else %} | |
{% set excerpt = excerpt %} | |
{% endif %} | |
<div class="c-search__result"> | |
<p> | |
<a href="{{ searchResult.uri }}"> | |
{% if searchResult['title'] is defined %} | |
<strong class="h3 strong"> | |
{{ searchResult.title }} | |
</strong> | |
{% endif %} | |
{{ excerpt|raw }} | |
</a> | |
</p> | |
</div> | |
{% endfor %} | |
{# Pagination #} | |
{% if amSearchPaginate.total > 1 %} | |
<a href="{{ amSearchPaginate.firstUrl }}">Erste Seite</a> | |
{% if amSearchPaginate.prevUrl %}<a href="{{ amSearchPaginate.prevUrl }}">Vorherige Seite</a>{% endif %} | |
{% for page, url in amSearchPaginate.getPrevUrls(5) %} | |
<a href="{{ url }}">{{ page }}</a> | |
{% endfor %} | |
<span class="current">{{ amSearchPaginate.currentPage }}</span> | |
{% for page, url in amSearchPaginate.getNextUrls(5) %} | |
<a href="{{ url }}">{{ page }}</a> | |
{% endfor %} | |
{% if amSearchPaginate.nextUrl %}<a href="{{ amSearchPaginate.nextUrl }}">Nächste Seite</a>{% endif %} | |
<a href="{{ amSearchPaginate.lastUrl }}">Letzte Seite</a> | |
{% endif %} | |
{% endif %} | |
</div> | |
</section> | |
{% endif %} | |
{% endblock %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment