{% sw_extends '@Storefront/storefront/utilities/thumbnail.html.twig' %}
{% block thumbnail_utility %}
{% if load is not defined %}
{% set load = true %}
{% endif %}
{% if loadOriginalImage is not defined %}
{% set loadOriginalImage = false %}
{% endif %}
{% if autoColumnSizes is not defined %}
{% set autoColumnSizes = true %}
{% endif %}
{% if attributes is not defined %}
{% set attributes = {} %}
{% endif %}
{% if attributes.loading is not defined %}
{% set attributes = attributes|merge({'loading': 'lazy'}) %}
{% endif %}
{% set altText = "" %}
{% if media.translated.alt|length and not (media.translated.alt == media.fileName) %}
{% set altText = media.translated.alt %}
{% else %}
{% set productTitle = product.translated.name ?? product.name %}
{% if productTitle|length %}
{% set altText = productTitle %}
{% endif %}
{% set productPageTitle = page.product.translated.name ?? page.product.name %}
{% if altText|length == 0 and productPageTitle|length %}
{% set altText = productPageTitle %}
{% endif %}
{% set linkHeadline = element.translated.config.linkHeadline.value ?? element.linkHeadline %}
{% if altText|length == 0 and linkHeadline|length %}
{% set altText = linkHeadline %}
{% endif %}
{% set pageTitle = page.cmsPage.translated.name %}
{% if altText|length == 0 and pageTitle|length %}
{% set altText = pageTitle %}
{% endif %}
{% if altText|length == 0 %}
{% set altText = media.fileName %}
{% endif %}
{% endif %}
{% set attributes = attributes|merge({'alt': altText}) %}
{% if attributes.title is not defined %}
{% set attributes = attributes|merge({'title': altText}) %}
{% endif %}
{% if media.thumbnails|length > 0 %}
{% if autoColumnSizes and columns and sizes is not defined %}
{% set sizes = {
'xs': (theme_config('breakpoint.sm') - 1) ~'px',
'sm': (theme_config('breakpoint.md') - 1) ~'px',
'md': ((theme_config('breakpoint.lg') - 1) / columns)|round(0, 'ceil') ~'px',
'lg': ((theme_config('breakpoint.xl') - 1) / columns)|round(0, 'ceil') ~'px'
} %}
{% if layout == 'full-width' %}
{% set container = 100 %}
{% set sizes = sizes|merge({ 'xl': (container / columns)|round(0, 'ceil') ~'vw'}) %}
{% else %}
{% set container = 1360 %}
{% set sizes = sizes|merge({ 'xl': (container / columns)|round(0, 'ceil') ~'px'}) %}
{% endif %}
{% endif %}
{% set thumbnails = media.thumbnails|sort|reverse %}
{% set srcsetValue %}{% apply spaceless %}
{% if loadOriginalImage %}{{ media|sw_encode_media_url }} {{ thumbnails|first.width + 1 }}w, {% endif %}{% for thumbnail in thumbnails %}{{ thumbnail.url | sw_encode_url }} {{ thumbnail.width }}w{% if not loop.last %}, {% endif %}{% endfor %}
{% endapply %}{% endset %}
{% set sizesValue %}{% apply spaceless %}
{% set sizeFallback = 100 %}
{% if autoColumnSizes and columns %}
{% set sizeFallback = (sizeFallback / columns)|round(0, 'ceil') %}
{% endif %}
{% set breakpoint = {
'xs': theme_config('breakpoint.xs'),
'sm': theme_config('breakpoint.sm'),
'md': theme_config('breakpoint.md'),
'lg': theme_config('breakpoint.lg'),
'xl': theme_config('breakpoint.xl')
} %}
{% if thumbnails|first.width > breakpoint|reverse|first %}
{#
@deprecated tag:v6.5.0 - Variable `maxWidth` and parent condition will be removed
#}
{% set maxWidth = thumbnails|first.width %}
{% endif %}
{% for key, value in breakpoint|reverse %}(min-width: {{ value }}px) {{ sizes[key] }}{% if not loop.last %}, {% endif %}{% endfor %}, {{ sizeFallback }}vw
{% endapply %}{% endset %}
{% endif %}
{{ block('thumbnail_utility_img') }}
{% endblock %}