templates/front/hotel/detail/_gallery.html.twig line 1

Open in your IDE?
  1. {# Galerie : image principale + images, dédoublonnées ; mosaïque desktop / carrousel scroll-snap mobile + modale Bootstrap #}
  2. {% set gallery = [] %}
  3. {% set gallery_urls = [] %}
  4. {% if hotel_data.thumbImage is defined and hotel_data.thumbImage is not empty %}
  5.     {% set gallery = gallery|merge([{url: hotel_data.thumbImage, alt: hotel_data.name}]) %}
  6.     {% set gallery_urls = gallery_urls|merge([hotel_data.thumbImage]) %}
  7. {% endif %}
  8. {% for image in hotel_data.images|default([]) %}
  9.     {% if image.url is not empty and image.url not in gallery_urls %}
  10.         {% set gallery = gallery|merge([{url: image.url, alt: image.alt ?: hotel_data.name}]) %}
  11.         {% set gallery_urls = gallery_urls|merge([image.url]) %}
  12.     {% endif %}
  13. {% endfor %}
  14. {% if gallery is empty %}
  15.     {% set gallery = [{url: asset('uploads/image_not_available.webp'), alt: hotel_data.name}] %}
  16. {% endif %}
  17. {% set gallery_count = gallery|length %}
  18. <div class="hd-gallery">
  19.     <div class="hd-pics hd-pics--{{ min(gallery_count, 3) }}" data-hotel-detail-target="gallery"
  20.          data-action="scroll->hotel-detail#updateCounter">
  21.         {% for image in gallery %}
  22.             <button type="button" class="hd-pic {{ loop.first ? 'hd-pic--main' : '' }} {{ loop.index > 3 ? 'hd-pic--extra' : '' }}"
  23.                     data-action="hotel-detail#openGallery" data-index="{{ loop.index0 }}"
  24.                     aria-label="{{ image.alt }} ({{ loop.index }}/{{ gallery_count }})">
  25.                 <img src="{{ image.url }}" alt="{{ image.alt }}"
  26.                      {{ loop.first ? 'fetchpriority="high"' : 'loading="lazy"' }}
  27.                      onerror="this.onerror=null;this.src='{{ asset('uploads/image_not_available.webp') }}';">
  28.             </button>
  29.         {% endfor %}
  30.     </div>
  31.     {% if gallery_count > 1 %}
  32.         <span class="hd-pics-counter" data-hotel-detail-target="counter">1 / {{ gallery_count }}</span>
  33.     {% endif %}
  34.     <button type="button" class="hd-pics-all" data-action="hotel-detail#openGallery" data-index="0">
  35.         <i class="bi bi-images" aria-hidden="true"></i>
  36.         {{ 'Pages.HotelDetail.SeeAllPhotos'|trans({'%count%': gallery_count}, 'messages_front') }}
  37.     </button>
  38. </div>
  39. <div class="modal fade hd-gallery-modal" id="hdGalleryModal" tabindex="-1" aria-hidden="true"
  40.      data-hotel-detail-target="galleryModal">
  41.     <div class="modal-dialog modal-xl modal-dialog-centered">
  42.         <div class="modal-content">
  43.             <div class="modal-header">
  44.                 <h5 class="modal-title">{{ hotel_data.name }}</h5>
  45.                 <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
  46.             </div>
  47.             <div class="modal-body">
  48.                 <div id="hdGalleryCarousel" class="carousel slide" data-bs-ride="false" data-bs-interval="false"
  49.                      data-hotel-detail-target="carousel">
  50.                     <div class="carousel-inner">
  51.                         {% for image in gallery %}
  52.                             <div class="carousel-item {{ loop.first ? 'active' : '' }}">
  53.                                 <img src="{{ image.url }}" alt="{{ image.alt }}" loading="lazy">
  54.                                 <div class="hd-carousel-caption">{{ loop.index }} / {{ gallery_count }}</div>
  55.                             </div>
  56.                         {% endfor %}
  57.                     </div>
  58.                     {% if gallery_count > 1 %}
  59.                         <button class="carousel-control-prev" type="button" data-bs-target="#hdGalleryCarousel" data-bs-slide="prev">
  60.                             <span class="carousel-control-prev-icon" aria-hidden="true"></span>
  61.                         </button>
  62.                         <button class="carousel-control-next" type="button" data-bs-target="#hdGalleryCarousel" data-bs-slide="next">
  63.                             <span class="carousel-control-next-icon" aria-hidden="true"></span>
  64.                         </button>
  65.                     {% endif %}
  66.                 </div>
  67.             </div>
  68.         </div>
  69.     </div>
  70. </div>