{% if contentList|length %}
    <div class="bloc-grille">
        <div class="container">
            <h2 class="h2-home-theme">
                {% if homeContent is defined and homeContent.fields.bloc_accueil_mini_sites_titre is defined and homeContent.getField('bloc_accueil_mini_sites_titre').value is not null %}
                    {{ ez_render_field(homeContent, 'bloc_accueil_mini_sites_titre') }}
                {% endif %}
            </h2>
            <ul class="grid">
                {% for id,contents in contentList %}
                    {% for index, content in contents %}
                        {# Default parameters #}
                        {% set link = "" %}
                        {% set target = 0 %}
                        {% set data_rel = 0 %}
                        {% set video_item = "" %}

                        {# Link #}
                        {% set link = get_link_by_content_id(content.id) %}
                        {% if ez_is_field_empty(content, 'lien_interne' ) and ez_is_field_empty(content, 'url' )
                            and content.fields.code_video is defined and not ez_is_field_empty(content, "code_video")  %}
                            {% set link = "#iframe_"~id~"_"~index %}
                            {% set video_item = "video-item" %}
                        {% endif %}

                        {# Target #}
                        {% if content.fields.nouvelle_fenetre is defined and not ez_is_field_empty(content, "nouvelle_fenetre")
                            and content.getFieldValue('nouvelle_fenetre').bool %}
                            {% set target = 1 %}
                        {% endif %}

                        {# Data Rel : prettyPhoto #}
                        {% if ez_is_field_empty(content, 'lien_interne' ) and ez_is_field_empty(content, 'url' )
                            and (content.fields.code_video is defined and not ez_is_field_empty(content,'code_video')) %}
                            {% set data_rel= 1 %}
                        {% endif %}

                        <li class="grid-item item{{ contents|length }}">
                            <div class="grid-item-in {{ video_item }}">
                                {% set type = "galerie" %}
                                {% if content.fields.lien_interne is defined and not ez_is_field_empty(content, "lien_interne") and content.getFieldValue("lien_interne").destinationContentId%}
                                    {% set contentType = load_content_by_content_id(content.getFieldValue("lien_interne").destinationContentId) %}
                                    {% if get_class_identifier(contentType.contentInfo.mainLocationId) == "gallery_video" %}
                                        {% set type = "video" %}
                                    {% endif %}
                                {% endif %}
                                <a title="{{ ez_content_name(content) }}" {% if type == "galerie" %}href="{{ link }}" {% if target %} target="_blank"{% endif %} {% if data_rel %} data-rel="prettyPhoto"{% endif %}{% else %}data-target="#video1" data-toggle="modal" href="#"{% endif %}>
                                    {% if content.getFieldValue('image').uri %}
                                        {{ ez_render_field(content, 'image', {'parameters': { 'alias': 'bloc_home' }}) }}
                                    {% endif %}

                                    {% if type == "video" %}
                                        <img src="/bundles/ayalinecollectivite/images/picto-play.png" alt="" class="play">
                                    {% else %}
                                        <img src="/bundles/ayalinecollectivite/images/svg/picto-gallery.svg" alt="" class="play">
                                    {% endif %}

                                    {% if content.fields.afficher_titre_bloc is defined and not ez_is_field_empty(content,'afficher_titre_bloc') and content.getFieldValue('afficher_titre_bloc').bool %}
                                        <div class="front">
                                            <div class="description">
                                                <h3>
                                                    {{ ez_field_value(content, "titre")|raw }}
                                                </h3>
                                            </div>
                                        </div>
                                    {% endif %}

                                    {% if ez_is_field_empty(content, 'lien_interne' ) and ez_is_field_empty(content, 'url' )
                                        and (content.fields.code_video is defined and not ez_is_field_empty(content,'code_video')) %}
                                        <span class="picto-video"></span>
                                        <div id="iframe_{{ id }}_{{ index }}" class="inline-content-galerie">
                                            {{ content.getFieldValue("code_video")|raw }}
                                        </div>
                                    {% endif %}

                                    <div class="back">
                                        <div class="description">
                                            <h3>
                                                {{ ez_field_value(content, "titre")|raw }}
                                            </h3>
                                            <p>
                                                {{ content.getFieldvalue('texte')|truncate(220, true, '...')|raw }}
                                            </p>
                                        </div>
                                    </div>
                                </a>
                            </div>
                        </li>
                        {% if type == "video" %}
                            <!-- Modal -->
                            <div aria-hidden="true" aria-labelledby="video1" role="dialog" tabindex="-1" id="video1" class="modal fade">
                                <div class="modal-dialog video">
                                    <div class="modal-content">
                                        <div>
                                            <div class="img-video video">
                                                <button title="Fermer" type="button" class="close" data-dismiss="modal"
                                                        aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                                {% set video =  ez_field_value( contentType, "video_tag") %}
                                                {{ video | raw }}
                                                <p class="video-title">{{ ez_render_field( contentType, "title" ) }}</p>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        {% endif %}
                    {% endfor %}
                {% endfor %}
            </ul>
            {% if homeContent is defined and homeContent.fields.bloc_accueil_mini_sites_lien is defined and homeContent.getField('bloc_accueil_mini_sites_lien').value.destinationContentId is not null %}
                {% set targetMediaLocationId = location_id_by_content_id(homeContent.getField('bloc_accueil_mini_sites_lien').value.destinationContentId) %}
                {% if targetMediaLocationId %}
                    <a href="{{ path( 'ez_urlalias', {'locationId': targetMediaLocationId  } ) }}"
                       class="voir-plus"
                       title="{{ ez_field_value(homeContent, 'bloc_accueil_mini_sites_titre_lien')|raw }}">{{ ez_field_value(homeContent, 'bloc_accueil_mini_sites_titre_lien')|raw }}</a>
                {% endif %}
            {% endif %}
        </div>
    </div>
{% endif %}