templates/includes/blocks/news-grid.html.twig line 20

  1. {# Get tags for news #}
  2. {% set tags = content.tags %}
  3. {# Get current locale #}
  4. {% set locale = app.request.locale|split('_')[0]|default('de') %}
  5. {# Get all news from database #}
  6. {% set news = news(tags) %}
  7. {# Get all smart contents from source 1 #}
  8. {% set stories = getDataFromSmartContent(content.stories, locale)|default([]) %}
  9. {# Get all smart contents from source 2 #}
  10. {% set publications = getDataFromSmartContent(content.publications, locale)|default([]) %}
  11. {# Get all smart contents from source 3 #}
  12. {% set pages = getDataFromSmartContent(content.pages, locale)|default([]) %}
  13. {# Sort by date DESC - Mix news and pages #}
  14. {% set sorted = sortByDate(stories, publications, pages, news, content.contentMixed) %}
  15. {% if (not content.expandEnabled or content.newsGridExpandButtonLabel is empty) and sorted|length > content.itemsCount %}
  16.     {#
  17.         Expanding is disabled, cut the list of items to the configured initial count
  18.         so we do not have unreachable image urls being pre-loaded
  19.     #}
  20.     {% set sorted = sorted|slice(0, content.itemsCount) %}
  21. {% endif %}
  22. <div class="teaser-grid {% if content.inverted %}teaser-grid--inverted {% endif %}{{ content.top }}
  23.   {{ content.bottom }}" x-data="teasergrid({{ sorted|length }},{{ content.itemsCount }},3)">
  24.     <div class="teaser-grid__container">
  25.         <div class="teaser-grid__teasers" x-ref="teasers" id="teasers">
  26.             {% for key, item in sorted %}
  27.                 {% set targetBlank = '' %}
  28.                 {% if item['url'] starts with 'http' %}
  29.                     {% set targetBlank = 'target="_blank"' %}
  30.                 {% endif %}
  31.                 <a href="{{ item['url'] }}"
  32.                    class="story-teaser {% if content.inverted %}story-teaser--inverted {% endif %}"
  33.                    x-show="show({{ key }})" {{ targetBlank }}>
  34.                     <div class="story-teaser__media">
  35.                         {# Image ID from News #}
  36.                         {% if item['image'] matches '/^\\d+$/' %}
  37.                             {% set image = sulu_resolve_media(item['image'], app.request.locale|split('_')[0]) %}
  38.                             <img src ="{{ image|thumbnailUrl('2880x') }}" class="story-teaser__image"
  39.                                  srcset ="{{ image|thumbnailUrl('320x') }} 320w, {{ image|thumbnailUrl('640x') }} 640w, {{ image|thumbnailUrl('1280x') }} 1280w, {{ image|thumbnailUrl('1440x') }} 1440w, {{ image|thumbnailUrl('2048x') }} 2048w" alt="{{ image.description|striptags }}"
  40.                                  x-ref="image" sizes="(min-width: 1440px) 480px, (min-width: 768px) 33vw, 100vw">
  41.                         {% elseif item['thumbnails'] is not empty %}
  42.                             {# Thumbnails array from Stories #}
  43.                             <img src="{{ item|thumbnailUrl('2880x') }}" class="story-teaser__image"
  44.                                  srcset="{{ item|thumbnailUrl('320x') }} 320w,  {{ item|thumbnailUrl('640x') }} 640w,
  45.                                          {{ item|thumbnailUrl('1280x') }} 1280w, {{ item|thumbnailUrl('1440x') }} 1440w,
  46.                                          {{ item|thumbnailUrl('2048x') }} 2048w" alt="{{ item.description|striptags }}"
  47.                                  x-ref="image" sizes="(min-width: 1440px) 480px, (min-width: 768px) 33vw, 100vw">
  48.                         {% endif %}
  49.                     </div>
  50.                     <div class="story-teaser__meta">
  51.                         <span class="story-teaser__type"
  52.                               style="float: left">{{ item['source'] }} |&nbsp;</span>
  53.                         <span class="story-teaser__time"><p>{{ item['dateGerman'] }}</span>
  54.                     </div>
  55.                     <div class="story-teaser__title">
  56.                         {{ item['title']|raw }}
  57.                     </div>
  58.                     <div class="story-teaser__text">
  59.                         {{ item['description']|raw }}
  60.                     </div>
  61.                 </a>
  62.             {% endfor %}
  63.         </div>
  64.         {# CSS for button and Javascript for Button required??? #}
  65.         {% if content.expandEnabled and content.newsGridExpandButtonLabel is not empty %}
  66.             <div class="teaser-grid__actions" x-ref="actions" x-show="showActions()" id="newsgrid-actions">
  67.                 <button class="button button--{% if content.inverted %}grey{% else %}default {% endif %}"
  68.                         x-ref="loadmore" @click="loadMore" id="moreButton-News">
  69.                    <span class="button__inner">
  70.                      {{ content.newsGridExpandButtonLabel }}
  71.                    </span>
  72.                 </button>
  73.             </div>
  74.         {% endif %}
  75.     </div>
  76. </div>