{# # ============================================================================ # MOLECULE: PAGINATION # ============================================================================ # # Composant de navigation paginée pour listes et tableaux. # # ============================================================================ # COMPOSITION (Atomes utilisés) # ============================================================================ # # - _atoms/icon/icon.html.twig # - _atoms/button/button.html.twig # # ============================================================================ # PARAMÈTRES # ============================================================================ # # | Paramètre | Type | Défaut | Description | # |---------------|---------|----------|-------------------------------------| # | currentPage | int | 1 | Page actuelle | # | totalPages | int | 1 | Nombre total de pages | # | baseUrl | string | '#' | URL de base (ajout de ?page=N) | # | pageParam | string | 'page' | Nom du paramètre de page | # | maxVisible | int | 5 | Nombre max de pages visibles | # | showFirstLast | bool | true | Afficher boutons première/dernière | # | showPrevNext | bool | true | Afficher boutons précédent/suivant | # | showInfo | bool | false | Afficher "Page X sur Y" | # | size | string | 'md' | sm, md, lg | # | variant | string | 'default'| default, moodia, minimal | # | class | string | '' | Classes additionnelles | # # ============================================================================ # EXEMPLES D'UTILISATION # ============================================================================ # # Pagination simple: # {% include '_molecules/pagination/pagination.html.twig' with { # currentPage: 3, # totalPages: 10, # baseUrl: '/courses' # } %} # # Avec infos: # {% include '_molecules/pagination/pagination.html.twig' with { # currentPage: page, # totalPages: lastPage, # baseUrl: path('course_list'), # showInfo: true # } %} # # ============================================================================ #} {# ============================================================================ CONFIGURATION DES VALEURS PAR DÉFAUT ============================================================================ #} {% set currentPage = currentPage ?? 1 %} {% set totalPages = totalPages ?? 1 %} {% set baseUrl = baseUrl ?? '#' %} {% set pageParam = pageParam ?? 'page' %} {% set maxVisible = maxVisible ?? 5 %} {% set showFirstLast = showFirstLast ?? true %} {% set showPrevNext = showPrevNext ?? true %} {% set showInfo = showInfo ?? false %} {% set size = size ?? 'md' %} {% set variant = variant ?? 'default' %} {% set class = class ?? '' %} {# ============================================================================ CLASSES TAILWIND ============================================================================ #} {% set sizeConfig = { 'sm': { 'button': 'w-8 h-8 text-xs', 'gap': 'gap-1', 'padding': 'px-2' }, 'md': { 'button': 'w-10 h-10 text-sm', 'gap': 'gap-1.5', 'padding': 'px-3' }, 'lg': { 'button': 'w-12 h-12 text-base', 'gap': 'gap-2', 'padding': 'px-4' } } %} {% set sConfig = sizeConfig[size] ?? sizeConfig['md'] %} {# Configuration variante Moodia #} {% set isMoodia = variant == 'moodia' %} {# Fonction pour générer l'URL d'une page #} {% set generateUrl = baseUrl ~ ('?' in baseUrl ? '&' : '?') ~ pageParam ~ '=' %} {# Calculer les pages à afficher #} {% set halfVisible = ((maxVisible - 1) / 2)|round(0, 'floor') %} {% set startPage = max(1, currentPage - halfVisible) %} {% set endPage = min(totalPages, startPage + maxVisible - 1) %} {% if endPage - startPage < maxVisible - 1 %} {% set startPage = max(1, endPage - maxVisible + 1) %} {% endif %} {# ============================================================================ RENDU HTML ============================================================================ #} {% if totalPages > 1 %} {% if isMoodia %} {# ===== VARIANTE MOODIA ===== #}
{% else %} {# ===== VARIANTE DEFAULT ===== #} {% endif %} {% endif %}