templates/news/index.html.twig line 1

Open in your IDE?
  1. {% extends 'base.html.twig' %}
  2. {% set totalPages = news['totalPages']|default() %}
  3. {% set total = news['total']|default() %}
  4. {% set limit = 10 %}
  5. {% set firstNews  = news['list']|slice(0, 1)|default([]) %}
  6. {% set secondNews = news['list']|slice(1, 4)|default([]) %}
  7. {% set restsNews  = news['list'][5:]|default([]) %}
  8. {% block page_contents %}
  9.   <section class="section section-page-title bg-gradient py-xl-5 py-4" data-aos='fade-down'>
  10.     <div class="container">
  11.       <div class="row">
  12.         <div class="col-12 text-center text-white">
  13.           <h1 class="page-name font-weight-bold my-2">{% trans %}Suivez les dernières actualités ÉSTIAM{% endtrans %}</h1>
  14.           <p class="mb-0">{%trans%}Retrouvez toute l'actualité de l'école ÉSTIAM : vie de l'école, pédagogie, événements, toutes les actualités par campus...{%endtrans%}</p>
  15.         </div>
  16.       </div>
  17.     </div>
  18.   </section>
  19.   <section class="section section-top-news py-4 mb-4">
  20.     <div class="container">
  21.       <div class="row">
  22.       
  23.         <div class="col-lg-6">
  24.           {% if firstNews %}
  25.           {% set news = (firstNews|first) %}
  26.           <div class="top-news d-flex flex-column h-100 mb-4 mr-xl-3 mt-3" data-aos='fade-right'>
  27.             <div class="t-img hover-zoom">
  28.               <a href="{{ news.url }}">
  29.                 <img class="w-100" src="{{ news.media }}" alt="{{ news.title }}" 
  30.                 onerror="this.onerror=null;this.src='{{ asset('assets/images/no-img/news.jpg') }}';"/>
  31.               </a>
  32.             </div>
  33.             <div class="p-xl-3 p-2">
  34.               <div class="n-title mb-3">
  35.                 <a href="{{ news.url }}">{{ news.title }}</a>
  36.               </div>
  37.               <div class="n-time mb-3">
  38.                 <div class="n-icon"><i class="fa-solid fa-calendar-week"></i></div>
  39.                 <div class="n-text">{{ news.createdDate|date('d M Y') }}</div>
  40.               </div>
  41.               <div class="n-text mb-3">
  42.                 <div class="truncate-text">
  43.                   {{ news.description }}
  44.                 </div>
  45.               </div>
  46.               <div class="n-link mt-auto">
  47.                 <a href="{{ news.url }}">{% trans %}Lire l'article{% endtrans %}<i class="fa-solid fa-arrow-right"></i></a>
  48.               </div>
  49.             </div>
  50.           </div>
  51.           {% endif %}
  52.         </div>
  53.         <div class="col-lg-6">
  54.           {% if secondNews %}
  55.           <div class="d-flex flex-column h-100 mb-4 ml-xl-2" data-aos='fade-left'>
  56.             {% for news in secondNews %}
  57.               <div class="related-item py-3 d-flex">
  58.                 <div class="r-content flex-1 d-flex flex-column h-100 py-2 mr-md-3 mr-2">
  59.                   <div class="r-title font-weight-bold mb-auto">
  60.                     <a href="{{ news.url }}">{{ news.title }}</a>
  61.                   </div>
  62.                   <div class="r-time my-md-3 my-2">
  63.                     <div class="r-icon"><i class="fa-solid fa-calendar-week"></i></div>
  64.                     <div class="r-text">{{ news.createdDate|date('d M Y') }}</div>
  65.                   </div>
  66.                   <div class="r-link mt-auto">
  67.                     <a href="{{ news.url }}">{% trans %}Lire l'article{% endtrans %}<i class="fa-solid fa-arrow-right"></i></a>
  68.                   </div>
  69.                 </div>
  70.                 <div class="r-img ml-auto">
  71.                   <div class="hover-zoom">
  72.                     <a href="{{ news.url }}"><img class="w-100" src="{{ news.media }}" alt="{{ news.title }}" 
  73.                     onerror="this.onerror=null;this.src='{{ asset('assets/images/no-img/news.jpg') }}';"/></a>
  74.                   </div>
  75.                 </div>
  76.               </div>
  77.             {% endfor %}
  78.           </div>
  79.           {% endif %}
  80.         </div>
  81.       </div>
  82.     </div>
  83.   </section>
  84.   {% if restsNews %}
  85.   <section class="section section-news b-4">
  86.     <div class="container">
  87.       <div class="row" id="load-more">
  88.         {% for news in restsNews %}
  89.         <div class="col-lg-4 col-md-6 mb-lg-5 mb-4">
  90.           <div class="n-item d-flex flex-column h-100" data-aos='zoom-in'>
  91.             <div class="n-img mb-4">
  92.               <a href="{{ news.url }}">
  93.                 <img class="position-relative w-100" src="{{ news.media }}" alt="{{ news.title }}" 
  94.                     onerror="this.onerror=null;this.src='{{ asset('assets/images/no-img/news.jpg') }}';"/>
  95.               </a>
  96.             </div>
  97.             <div class="n-title mb-3">
  98.               <a href="{{ news.url }}">{{ news.title }}</a>
  99.             </div>
  100.             <div class="n-time mb-3">
  101.               <div class="n-icon"><i class="fa-solid fa-calendar-week"></i></div>
  102.               <div class="n-text">{{ news.createdDate|date('d M Y') }}</div>
  103.             </div>
  104.             <div class="n-text mb-3">
  105.               <div class="truncate-text">
  106.                 {{ news.description }}
  107.               </div>
  108.             </div>
  109.             <div class="n-link mt-auto">
  110.               <a href="{{ news.url }}">{% trans %}Lire l'article{% endtrans %}<i class="fa-solid fa-arrow-right"></i></a>
  111.             </div>
  112.           </div>
  113.         </div>
  114.         {% endfor %}
  115.       </div>
  116.       {% if totalPages > 1 %}
  117.           <div class="row mt-4 mb-5" data-aos='fade-up'>
  118.               <div class="col-12 text-center listing-loading" style="display: none;">
  119.                   <div class="loading">
  120.                   <div class="dot"></div>
  121.                   <div class="dot"></div>
  122.                   <div class="dot"></div>
  123.                   <div class="dot"></div>
  124.                   <div class="dot"></div>
  125.                   </div>
  126.               </div>
  127.           </div>
  128.         {% endif %}
  129.     </div>  
  130.   </section>
  131.   {% endif %}
  132. {% endblock %}
  133. {% block custom_javascripts %}
  134. {{ '<script type="application/ld+json">'|raw }}
  135. {{ richSnippets|json_encode | raw }}
  136. {{ '</script>'|raw }}
  137. <script type="text/javascript">
  138. $(document).ready(function(){
  139.     $('.load__more').hide();
  140.     const totalPages = '{{ totalPages }}';
  141.     const total = '{{ total }}';
  142.     const limit = '{{ limit }}';
  143.     let page = 1;
  144.     let process = true;
  145.     $('.view-more .link-btn').click(function(){
  146.         if(process && totalPages > 1){
  147.             $('.listing-paging').hide();
  148.             $('.listing-loading').show();
  149.             getmoredata();
  150.         }
  151.     });
  152.     $(window).scroll(function () {
  153.         let height = ($(window).scrollTop() + $(window).height()+ 400);
  154.         if(height >= $(document).height()){
  155.             if(process && totalPages > 1){
  156.                 $('.listing-loading').show();
  157.                 getmoredata();
  158.             }
  159.         }
  160.     })
  161.     function getmoredata() {
  162.         process = false;
  163.         $.ajax({
  164.             type: "GET",
  165.             url: "{{ path('news.loadMore') }}",
  166.             dataType: "json",
  167.             data:{'page':page,'limit':limit},
  168.             success: function (response) {
  169.                 $('.listing-loading').hide();
  170.                 
  171.                 if(response.list){
  172.                     $('#load-more').append(response.list);
  173.                     $('.item-more .truncate-text').each(function() {
  174.                         var $div = $(this);
  175.                         var divWords = $div.text().split(/\s+/);
  176.                         $div.empty();
  177.                         $.each(divWords, function(i,w){
  178.                             $('<span/>').text(w).appendTo($div);
  179.                         });
  180.                         $(this).parent('.item-more').removeClass('item-more');
  181.                     });
  182.                 }
  183.                 page = page + 1;
  184.                 
  185.                 let processWidth = (((parseInt($('#news-seen').text()) + limit) / total) *100);
  186.                  $('.progress').css({'width': processWidth+'%'});
  187.                 if(page*limit < total){
  188.                     process = true;
  189.                     $('#news-seen').text(parseInt($('#news-seen').text()) + limit);
  190.                     $('.listing-paging').show();
  191.                 }
  192.                 AOS.init({
  193.                     easing: 'ease-out-back',
  194.                     offset: 150,
  195.                     disable: 'mobile'
  196.                 });
  197.             }
  198.         });
  199.     }
  200. });
  201. </script>
  202. {% endblock %}