{% extends 'partials/base.html.twig' %}

{% set bodyclass = "projet" %}

{% set images = page.media.images[1:] %}
{% set images = images|merge(page.media.files) %}

{% block content %}
  <section class="projet">
    <h1>{{page.title}}</h1>
    <h2>{{ page.header.subtitle}}</h2>

    {{ page.content }}

    <div id="images" class="">
      {{ dump(images) }}

      {# set temporary array to be able to look trough images with index #}
      {% set numberedKeys = {} %}
      {% for key,value in images %}
        {% set numberedKeys = numberedKeys|merge({(loop.index):(key)}) %}
      {% endfor %}
      {{dump(numberedKeys)}}

      {# display images #}
      {% set continue = false %}

      {% for image in images %}
        {% if not continue %}
          <div class="row">

            {% if image.meta.size == 1 %}
              <div class="block block-{{loop.index}} column large-12">
                {{ image.html }}
              </div>
            {% else %}
              {% set nextimage = images[numberedKeys[loop.index]] %}
              {{ dump(nextimage) }}
              {% if nextimage.meta.size != 1 %}
                {% set continue = true %}
                <div class="block block-{{loop.index}} column large-6">
                  {{ image.resize(1000).html }}
                </div>
                <div class="block block-{{loop.index+1}} column large-6">
                  {{ nextimage.resize(1000).html }}
                </div>
              {% else %}
                <div class="block block-{{loop.index}} column large-6">
                  {{ image.resize(1000).html }}
                </div>
                <div class="block empty column large-6"></div>
              {% endif %}

            {% endif %}

          </div>
        {% else %}
          {% set continue = false %}
        {% endif %}
      {% endfor %}

    </div>
  </section>

  <nav class="categories">
    {% include 'partials/tagslist.html.twig' with {'base_url':"/categories/", 'taxonomy':'tag', 'display':'inline'} %}
  </nav>

{% endblock %}
