title = "Gözleg"
url = "/search"
layout = "default"
is_hidden = 0

[viewBag]
localeTitle[ru] = "Поиск"
localeTitle[en] = "Search"
localeUrl[ru] = "/search"
localeUrl[en] = "/search"

==
<?php
function onStart(){
    $this['search_results'] = \Indikator\News\Models\Posts::search(
        input("query"))->orderBy('published_at', 'desc')->paginate(10);

    $this['query'] = input("query");
}
?>
==
<section class="section" id="intro">
    <div class="auto_container">
        <div class="which_page">
            <a href="{{ 'index'|page}}">

                <div class="page_name">
                    {{'Главная'|_}}
                </div>
            </a>
            <div class="slash">\</div>
            <div class="page_name">
                {{'Результат поиска'|_}}
            </div>
        </div>
        <div class="section_wrapper">
            <div class="center">
                <div class="title">
                    {{'Результат поиска'|_}}
                </div>
                <div class="main_news">
                    {% for item in search_results %}
                        <div class="main_news-item">
                            <div class="main_news-date">
                                <span>
                                    {{ item.published_at| date("d.m") }}
                                </span>
                                <span>
                                    {{ item.published_at| date("Y") }}
                                </span>
                            </div>
                            <div class="main_news-content">
                                <div class="main_news-title">

                                    <a href="{{ 'post'|page ({id: item.id, slug: item.slug})}}">
                                    {{item.title}}
                                    </a>
                                </div>
                                <div class="main_news-text">

                                    {{ item.introductory|raw }}
                                </div>
                            </div>
                        </div>
                    {% endfor %}
                </div>

                {% if search_results.total > 10 %}
                    <div class="section_end">
                        <div class="page_num">
                            <a href="{{search_results.previousPageUrl}}">
                                <div class="direct_btn">
                                        <img src="{{ 'assets/images/left.svg'|theme }}" alt="">
                                </div>
                            </a>
                            <form action="" method="GET">
                                <input type="hidden" name="query" value="{{query}}" />
                                <input type="text" name="page" value="{{search_results.currentPage}}" class="input_page">
                            </form>
                            <a href="{{search_results.nextPageUrl}}">
                                <div class="direct_btn">
                                        <img src="{{ 'assets/images/right.svg'|theme }}" alt="">
                                </div>
                            </a>
                        </div>
                        <div class="page_list">
                            {{(search_results.total/search_results.perPage)|round(0,"ceil")}} {{'страниц'|_}}
                        </div>
                    </div>
                {% endif %}
            </div>
            <div class="right_side full">
                <div class="title">
                    {{'Поиск'|_}}
                </div>
                <form class="form" method="GET">
                    <div class="input">
                        <input type="text" name="query" placeholder="Поиск">
                    </div>
                    <button class="search">
                            <img src="{{ 'assets/images/lupa.svg'|theme }}" alt="">
                    </button>
                </form>
                <div class="found_news">
                    {{'По вашему запросу было найдено'|_}} <span class="quantity_num">{{search_results.total}}</span> {{'статей'|_}}
                </div>
            </div>
        </div>
    </div>
</section>
