{% extends 'base.html.twig' %}
{% block title %}
{{ meta_title }}
{% endblock %}
{% block meta_description %}
<meta name="description" content="{{ meta_description }}">
{% endblock %}
{% block body %}
<h1 class="text-3xl font-semibold my-8 text-center mx-auto uppercase">{{ genre }}</h1>
{% if description %}
<p class="text-lg text-center mx-auto mb-4 max-w-2xl">{{ description }}</p>
{% endif %}
<div class="flex items-center justify-center py-4 md:py-8 flex-wrap mb-8">
{% set selectedGenreSlug = selectedGenre %}
{% set allActive = selectedGenreSlug == 'all' %}
<button type="button" class="{% if allActive %}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{% else %}hover:text-white hover:bg-blue-700 text-gray-900 border-2 border-white hover:border-gray-200 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{% endif %}">
<a href="{{ path('photo_gallery') }}">Все жанры</a>
</button>
{% for genre in genres %}
{% set genreSlug = genre %}
{% set isActive = selectedGenreSlug == genreSlug %}
<button type="button" class="{% if isActive %}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{% else %}hover:text-white hover:bg-blue-700 text-gray-900 border-2 border-white hover:border-gray-200 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{% endif %}">
<a href="{{ path('photos_by_genre', {'genre': genreSlug}) }}">{{ genre }}</a>
</button>
{% endfor %}
</div>
<div class="container mx-auto px-4 pb-2">
<div class="masonry">
{% for photo in photos %}
<div class="masonry-item">
<a href="{{ path('photo_show', {'genre': photo.genre, 'id': photo.id}) }}">
<div class="image-container">
{% if photo.path %}
<img class="h-auto max-w-full rounded-lg" src="{{ asset('photos/' ~ photo.path) }}" alt="{{ photo.title }}">
{% else %}
<img class="h-auto max-w-full rounded-lg" src="{{ asset('photos/default.jpg') }}" alt="Изображение по умолчанию">
{% endif %}
<div class="image-overlay">
<p class="image-text">Посмотреть</p>
</div>
</div>
</a>
</div>
{% endfor %}
</div>
</div>
<style>
.masonry {
column-count: 3;
column-gap: 20px;
}
.masonry-item {
break-inside: avoid;
padding: 1rem;
background-color: #f0f0f0;
border: 1px solid #ccc;
display: inline-block;
margin-bottom: 1rem;
width: 100%;
box-sizing: border-box;
}
.image-container {
position: relative;
}
.image-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
opacity: 0;
transition: opacity 0.3s ease;
}
.image-text {
color: #fff;
font-size: 18px;
font-weight: bold;
}
.image-container:hover .image-overlay {
opacity: 1;
}
</style>
<script src="https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.min.js"></script>
<script>
window.addEventListener('load', () => {
// Функция для обновления количества колонок в masonry в зависимости от ширины экрана
function updateMasonryColumns() {
const masonry = document.querySelector('.masonry');
if (!masonry) {
console.warn('Masonry layout container not found.');
return;
}
const screenWidth = window.innerWidth;
if (screenWidth > 1200) {
masonry.style.columnCount = 4;
} else if (screenWidth > 768) {
masonry.style.columnCount = 3;
} else {
masonry.style.columnCount = 2;
}
console.log('Column count:', masonry.style.columnCount);
}
// Проверка каждого изображения внутри masonry, чтобы убедиться, что src определен
const images = document.querySelectorAll('.masonry-item img');
images.forEach((img) => {
if (!img.src) {
console.warn('Image src is undefined or empty.');
}
});
// Начальная настройка и обновление masonry при изменении размера окна
updateMasonryColumns();
window.addEventListener('resize', updateMasonryColumns);
});
</script>
{% endblock %}