src/Package/Openform/Front/Templates/Search/index.html.twig line 1

Open in your IDE?
  1. {% extends "@openform_front_templates/base.html.twig" %}
  2. {% block bodyAttr %}data-page="index-page"{% endblock %}
  3. {% from '@openform_front_templates/_includes/_icons.html.twig' import search %}
  4. {% set pageSubTitle = entity.Translation[app.request.locale].title %}
  5. {% set metaTitle = entity.Translation[app.request.locale].metaTitle ? entity.Translation[app.request.locale].metaTitle : entity.Translation[app.request.locale].title %}
  6. {% set metaDescription = entity.Translation[app.request.locale].metaDescription %}
  7. {% set metaKeywords = entity.Translation[app.request.locale].metaKeywords %}
  8. {% set pageImage = entity.imagePath ? openform_front_util.getImagePathByType(entity.Thumb,'list') : '' %}
  9. {% block content %}
  10.     
  11.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  12.     <section class="search-result container">
  13.         <div class="search-result__title">
  14.             {{'SEARCH_RESULTS_FOR_PHRASE'|trans({}, 'openform_front', app.request.locale)}} "{{ filters.phrase is defined ? filters.phrase }}"
  15.         </div>
  16.         <div class="search-result__wrapper">
  17.             <div class="search-result-list" >
  18.                 {% include '@openform_front_templates/Search/_list.html.twig' %}
  19.             </div>
  20.             <div class="search-result__info">
  21.                 {% include '@openform_front_templates/Search/_filters.html.twig' %}
  22.             </div>
  23.         </div>
  24.     </section>
  25.     <script>
  26.         var loadAjax;
  27.         jQuery(function ($) {
  28.             loadAjax = function (page) {
  29.                 addUrlParam('page', page)
  30.                 $.ajax({
  31.                     'url': '{{ toolkit_route_localizer.generate('search_filter_ajax',{} ,app.request.locale) }}',
  32.                     'type': 'POST',
  33.                     'dataType': 'json',
  34.                     'contentType': 'application/json; charset=utf-8',
  35.                     'data': JSON.stringify({
  36.                         page: page,
  37.                         filters: queryStringToObject(window.location.search)
  38.                     }),
  39.                     'success': function (response) {
  40.                         $('.search-result-list').html(response.entitiesHtml)
  41.                     }
  42.                 });
  43.             }
  44.         });
  45.         function queryStringToObject(queryString) {
  46.             const params = new URLSearchParams(queryString);
  47.             const result = {};
  48.             params.forEach((value, key) => {
  49.                 if (key.endsWith("[]")) {
  50.                     const realKey = key.slice(0, -2);
  51.                     if (!result[realKey]) {
  52.                         result[realKey] = [];
  53.                     }
  54.                     if (value && value.length) {
  55.                         result[realKey].push(value);
  56.                     }
  57.                 } else {
  58.                     if (value) {
  59.                         result[key] = value;
  60.                     }
  61.                 }
  62.             });
  63.             return result;
  64.         }
  65.         function addUrlParam(paramName, value) {
  66.             const currentUrl = window.location.href;
  67.             const urlParams = new URLSearchParams(window.location.search);
  68.             urlParams.set(paramName, value);
  69.             const nowyURL = `${window.location.pathname}?${urlParams.toString()}${window.location.hash}`;
  70.             window.history.pushState({path: nowyURL}, '', nowyURL);
  71.         }
  72.     </script>
  73. {% endblock %}