{% load wagtailcore_tags wagtailimages_tags i18n el_pagination_tags %}

{% block content %}
{% if results %}

  {% paginate 10 results as paginated_results %}
  {% for page in paginated_results %}
    {% with parent_section=page.get_parent_section ancestor=page.get_parent_section.get_ancestors.last %}
      <a href="{% pageurl page %}">
          {% if ancestor.sectionpage.image %}
              <h6>{{ancestor.title}}</h6>
          {% else %}
              <h6>{{parent_section.title}}</h6>
          {% endif %}
          {% if page.title_highlight %}
              <h3>{{page.title_highlight|safe}}</h3>
          {% else %}
              <h3>{{page.title}}</h3>
          {% endif %}
          {% if page.subtitle_highlight or page.body_highlight %}
              {% if page.subtitle_highlight %}
                  <p>{{page.subtitle_highlight|safe}}</p>
              {% elif page.body_highlight %}
                  <p>{{page.body_highlight|safe}}</p>
              {% endif %}
          {% else %}
              <p>{{page.subtitle}}</p>
          {% endif %}
      </a>
    {% endwith %}
  {% endfor %}

  <div id="pagination">
    {% include "patterns/basics/pagination/pagination-pageof.html" %}
  </div>
  {% get_pages %}
  {% if pages.next %}
    <a id="more-link" class="call-to-action call-to-action__item more-link" href="#" data-next="{% url 'search_index' %}?page={{pages.next.number}}&q={{search_query}}&locale={{locale_code}}">Load More</a>
  {% endif %}

  {% endif %}
{% endblock %}

{% block search %}
  {% if search_results %}
      {% include "search/search_block.html" %}
  {% endif %}
{% endblock %}
