templates/photo/gallery.html.twig line 1

Open in your IDE?
  1. {% extends 'base.html.twig' %}
  2. {% block title %}Галерея картин – Николай Макаров{% endblock %}
  3. {% block body %}
  4.   <h1 class="text-3xl font-semibold my-8 text-center mx-auto">Галерея</h1>
  5.   <div class="flex items-center justify-center py-4 md:py-8 flex-wrap mb-8">
  6.     <button type="button" class="text-blue-700 hover:text-white border-2 border-blue-600 bg-white hover:bg-blue-700 focus:ring-4 focus:outline-none focus:ring-blue-300 rounded-full text-base font-medium px-5 py-2.5 text-center mr-3 mb-3 dark:border-blue-500 dark:text-blue-500 dark:hover:text-white dark:hover:bg-blue-500 dark:bg-gray-900 dark:focus:ring-blue-800" aria-label="Показать все жанры">
  7.       <a href="{{ path('photo_gallery') }}">Все жанры</a>
  8.     </button>
  9.     {% for genre in genres %}
  10.       {% set isNonFiction = 'non-fiction' in genre %}
  11.       {% if not isNonFiction %}
  12.         <button type="button" class="hover:text-white hover:bg-blue-700 dark:border-blue-500 dark:text-blue-500 dark:hover:text-white dark:hover:bg-blue-500 dark:focus:ring-blue-800 text-gray-900 border-2 border-white hover:border-gray-200 dark:border-gray-900 dark:bg-gray-900 dark:hover:border-gray-700 bg-white focus:ring-4 focus:outline-none focus:ring-gray-300 rounded-full text-base font-medium px-5 py-2.5 text-center mr-3 mb-3 dark:text-white dark:focus:ring-gray-800" aria-label="Показать жанр {{ genre|join(', ') }}">
  13.           <a href="{{ path('photos_by_genre', {'genre': genre|join(',')}) }}">{{ genre|join(', ') }}</a>
  14.         </button>
  15.       {% endif %}
  16.     {% endfor %}
  17.   </div>
  18.   <div class="container mx-auto px-4 pb-2">
  19.     <div class="masonry">
  20.       {% for photo in photos %}
  21.         {% if 'non-fiction' not in photo.genre %}
  22.           <div class="masonry-item">
  23.             <a href="{{ path('photo_show', {'genre': photo.genre, 'id': photo.id}) }}" aria-label="Просмотр картины {{ photo.title }}">
  24.               <div class="image-container" role="img" aria-label="Картина {{ photo.title }}">
  25.                 <img class="h-auto max-w-full rounded-lg" src="{{ asset('photos/' ~ photo.path) }}" alt="Картина '{{ photo.title }}' в жанре {{ photo.genre }}" loading="lazy" width="200" height="300">
  26.                 <div class="image-overlay" aria-hidden="true">
  27.                   <p class="image-text">Посмотреть</p>
  28.                 </div>
  29.               </div>
  30.             </a>
  31.           </div>
  32.         {% endif %}
  33.       {% endfor %}
  34.     </div>
  35.   </div>
  36.   <style>
  37.     /* Основной стиль сетки */
  38.     .masonry {
  39.       display: flex;
  40.       flex-wrap: wrap;
  41.       gap: 20px;
  42.     }
  43.     .masonry-item {
  44.       flex: 1 1 30%;
  45.       max-width: 30%;
  46.       background-color: #f0f0f0;
  47.       border: 1px solid #ccc;
  48.       padding: 1rem;
  49.       box-sizing: border-box;
  50.       margin-bottom: 1rem;
  51.     }
  52.     @media (max-width: 1200px) {
  53.       .masonry-item {
  54.         flex: 1 1 45%;
  55.         max-width: 45%;
  56.       }
  57.     }
  58.     @media (max-width: 768px) {
  59.       .masonry-item {
  60.         flex: 1 1 100%;
  61.         max-width: 100%;
  62.       }
  63.     }
  64.     .image-container {
  65.       position: relative;
  66.     }
  67.     .image-overlay {
  68.       position: absolute;
  69.       top: 0;
  70.       left: 0;
  71.       width: 100%;
  72.       height: 100%;
  73.       background-color: rgba(0, 0, 0, 0.5);
  74.       display: flex;
  75.       justify-content: center;
  76.       align-items: center;
  77.       opacity: 0;
  78.       transition: opacity 0.3s ease;
  79.     }
  80.     .image-text {
  81.       color: #fff;
  82.       font-size: 18px;
  83.       font-weight: bold;
  84.     }
  85.     .image-container:hover .image-overlay {
  86.       opacity: 1;
  87.     }
  88.   </style>
  89.   <!-- Подключение Masonry.js для более точной расстановки элементов -->
  90.   <script src="https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.min.js"></script>
  91.   
  92.   <script>
  93.     // Инициализация Masonry после загрузки
  94.     document.addEventListener('DOMContentLoaded', function () {
  95.       const masonry = new Masonry('.masonry', {
  96.         itemSelector: '.masonry-item',
  97.         columnWidth: '.masonry-item',
  98.         percentPosition: true,
  99.         gutter: 20
  100.       });
  101.     });
  102.   </script>
  103. {% endblock %}