templates/templates/blog.html.twig line 1

Open in your IDE?
  1. {% extends "master.html.twig" %}
  2. {% block meta %}
  3.     {% include "@SuluWebsite/Extension/seo.html.twig" with {
  4.         "seo": extension.seo|default([]),
  5.         "content": content|default([]),
  6.         "urls": urls|default([]),
  7.         "shadowBaseLocale": shadowBaseLocale|default(),
  8.         "defaultLocale": request.defaultLocale|default('de')
  9.     } %}
  10. {% endblock %}
  11. {% block style %}    
  12.     <link rel="stylesheet" href="{{ absolute_url(asset("build/website/css/blog.css")) }}">
  13. {% endblock %}
  14. {% block bgImages %}
  15.     {% for image in content.images %}
  16.         {{ image.url }}
  17.     {% endfor %}
  18. {% endblock %}
  19. {% block ogImages %}{% for image in content.images %}{{ image.url }}{% endfor %}{% endblock %}
  20. {% block content %}
  21.     <div class="content-actu">
  22.         <div class="filter">
  23.             {# define array and merge in if tag name doesn't exist #}
  24.             {% set tagsName = [] %}
  25.             <div class="filter-tag all active" data-id="empty">
  26.                 Tout
  27.             </div>
  28.             {% for article in content.articles %}
  29.                 {% for tag in article.excerpt.tags %}
  30.                     {% if tag.name not in tagsName %}
  31.                         {% set tagsName = tagsName|merge([tag.name]) %}
  32.                             <div class="filter-tag {{ " " }} {{ tag.name|lower|replace({ 'á':'a', 'é':'e', 'í':'i', 'ó':'o', 'ú':'u' }) }}" data-id="{{ tag.name|lower|replace({ 'á':'a', 'é':'e', 'í':'i', 'ó':'o', 'ú':'u' }) }}">
  33.                                 {{ tag.name|replace({'-':' '}) }}
  34.                             </div>
  35.                     {% endif %}
  36.                 {% endfor %}
  37.             {% endfor %}
  38.         </div>    
  39.         <div class="teaser_actus">
  40.             {% for article in content.articles %}
  41.                 {% if article.excerpt.tags|length > 0 %}
  42.                     <div class="container-article {{ " " }} {% for tag in article.excerpt.tags %}{{ tag.name|lower|replace({ 'á':'a', 'é':'e', 'í':'i', 'ó':'o', 'ú':'u' }) }}{{ " " }}{% endfor %}" style="display: block">
  43.                         <article class="article">
  44.                             <a class="img-actu" href="{{ sulu_content_path(article.content.content.routePath) }}">
  45.                                 <div class="tags {{ " " }} {{ article.excerpt.tags|first.name|lower|replace({ 'á':'a', 'é':'e', 'í':'i', 'ó':'o', 'ú':'u' })  }}">{{article.excerpt.tags|first.name|replace({'-':' '})|lower  }}</div>
  46.                                 {% if article.content.content.banner %}
  47.                                     <div class="image lazy" data-src="{{  article.content.content.banner[0].url }}"></div>
  48.                                 {% endif %}
  49.                             </a>
  50.                             <div>
  51.                                 <div class="date_actu">{{ article.authored|date("d / m / Y") }}</div>
  52.                                 <h2><a href="{{ sulu_content_path(article.content.content.routePath) }}">{{ article.title }}</a></h2>
  53.                                 <button aria-label="more" class="btn btn-light"><a href="{{ sulu_content_path(article.content.content.routePath) }}">En savoir plus</a></button>
  54.                             </div>
  55.                         </article>
  56.                     </div>
  57.                 {% endif %}
  58.             {% endfor %}
  59.         </div>
  60.     </div>
  61.     
  62. {% endblock %}
  63. {% block javascripts %}
  64.     <script>
  65. $(document).ready(function() {
  66.     function applyTagFilter(tag) {
  67.         if (tag === "empty") {
  68.             $(".filter .active-tag").removeClass("active-tag");
  69.             $(".all").addClass('active');
  70.             $(".container-article").show();
  71.         } else {
  72.             $(".all").removeClass('active');
  73.             $(".filter .active-tag").removeClass("active-tag");
  74.             $(`[data-id="${tag}"]`).addClass("active-tag");
  75.             $(".container-article").show();
  76.             var choice = "." + tag;
  77.             if (choice) {
  78.                 $(".container-article").not(choice).hide();
  79.             }
  80.         }
  81.         $(".article").removeClass("right left");
  82.         $(".container-article:visible article").each(function(index, el) {
  83.             if (index % 2 !== 0) {
  84.                 $(el).addClass("right");
  85.             } else {
  86.                 $(el).addClass("left");
  87.             }
  88.         });
  89.     }
  90.     // Lire l'URL actuelle et appliquer le filtre si un tag est présent
  91.     var urlParams = new URLSearchParams(window.location.search);
  92.     var initialTag = urlParams.get('tag');
  93.     if (initialTag) {
  94.         applyTagFilter(initialTag);
  95.     }
  96.     // Événement pour les clics sur les tags
  97.     $('.filter-tag').click(function(e) {
  98.         var tag = $(this).attr("data-id");
  99.         if (tag === "empty") {
  100.             history.pushState(null, '', window.location.pathname);
  101.         } else {
  102.             history.pushState(null, '', window.location.pathname + '?tag=' + tag);
  103.         }
  104.         applyTagFilter(tag);
  105.     });
  106.     // Événement pour la navigation dans l'historique
  107.     window.addEventListener('popstate', function() {
  108.         var tag = new URLSearchParams(window.location.search).get('tag');
  109.         applyTagFilter(tag || "empty");
  110.     });
  111. });
  112.     </script>
  113.     <script>window.breadcrumbMap={'json-ld-breadcrumb':'JSON-LD Breadcrumb'}</script>
  114. {% endblock %}