templates/includes/blocks/news-grid.html.twig line 1
{# Get tags for news #}
{% set tags = content.tags %}
{# Get current locale #}
{% set locale = app.request.locale|split('_')[0]|default('de') %}
{# Get all news from database #}
{% set news = news(tags) %}
{# Get all smart contents from source 1 #}
{% set stories = getDataFromSmartContent(content.stories, locale)|default([]) %}
{# Get all smart contents from source 2 #}
{% set publications = getDataFromSmartContent(content.publications, locale)|default([]) %}
{# Get all smart contents from source 3 #}
{% set pages = getDataFromSmartContent(content.pages, locale)|default([]) %}
{# Sort by date DESC - Mix news and pages #}
{% set sorted = sortByDate(stories, publications, pages, news, content.contentMixed) %}
{% if (not content.expandEnabled or content.newsGridExpandButtonLabel is empty) and sorted|length > content.itemsCount %}
{#
Expanding is disabled, cut the list of items to the configured initial count
so we do not have unreachable image urls being pre-loaded
#}
{% set sorted = sorted|slice(0, content.itemsCount) %}
{% endif %}
<div class="teaser-grid {% if content.inverted %}teaser-grid--inverted {% endif %}{{ content.top }}
{{ content.bottom }}" x-data="teasergrid({{ sorted|length }},{{ content.itemsCount }},3)">
<div class="teaser-grid__container">
<div class="teaser-grid__teasers" x-ref="teasers" id="teasers">
{% for key, item in sorted %}
{% set targetBlank = '' %}
{% if item['url'] starts with 'http' %}
{% set targetBlank = 'target="_blank"' %}
{% endif %}
<a href="{{ item['url'] }}"
class="story-teaser {% if content.inverted %}story-teaser--inverted {% endif %}"
x-show="show({{ key }})" {{ targetBlank }}>
<div class="story-teaser__media">
{# Image ID from News #}
{% if item['image'] matches '/^\\d+$/' %}
{% set image = sulu_resolve_media(item['image'], app.request.locale|split('_')[0]) %}
<img src ="{{ image|thumbnailUrl('2880x') }}" class="story-teaser__image"
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 }}"
x-ref="image" sizes="(min-width: 1440px) 480px, (min-width: 768px) 33vw, 100vw">
{% elseif item['thumbnails'] is not empty %}
{# Thumbnails array from Stories #}
<img src="{{ item|thumbnailUrl('2880x') }}" class="story-teaser__image"
srcset="{{ item|thumbnailUrl('320x') }} 320w, {{ item|thumbnailUrl('640x') }} 640w,
{{ item|thumbnailUrl('1280x') }} 1280w, {{ item|thumbnailUrl('1440x') }} 1440w,
{{ item|thumbnailUrl('2048x') }} 2048w" alt="{{ item.description|striptags }}"
x-ref="image" sizes="(min-width: 1440px) 480px, (min-width: 768px) 33vw, 100vw">
{% endif %}
</div>
<div class="story-teaser__meta">
<span class="story-teaser__type"
style="float: left">{{ item['source'] }} | </span>
<span class="story-teaser__time"><p>{{ item['dateGerman'] }}</span>
</div>
<div class="story-teaser__title">
{{ item['title']|raw }}
</div>
<div class="story-teaser__text">
{{ item['description']|raw }}
</div>
</a>
{% endfor %}
</div>
{# CSS for button and Javascript for Button required??? #}
{% if content.expandEnabled and content.newsGridExpandButtonLabel is not empty %}
<div class="teaser-grid__actions" x-ref="actions" x-show="showActions()" id="newsgrid-actions">
<button class="button button--{% if content.inverted %}grey{% else %}default {% endif %}"
x-ref="loadmore" @click="loadMore" id="moreButton-News">
<span class="button__inner">
{{ content.newsGridExpandButtonLabel }}
</span>
</button>
</div>
{% endif %}
</div>
</div>