{# activate load per default. If it is not activated only a data-src is set instead of the src tag. #}
{% if load is not defined %}
{% set load = true %}
{% endif %}
{# By default no original image will be loaded as soon as thumbnails are available. #}
{# When set to true the orginal image will be loaded when the viewport is greater than the largest available thumbnail. #}
{% if loadOriginalImage is not defined %}
{% set loadOriginalImage = false %}
{% endif %}
{# By default the srcset sizes will be calculated automatically if `columns` are present and no `sizes` are configured. #}
{# When set to false the sizes attribute will not be generated automatically. #}
{% if autoColumnSizes %}
{% set autoColumnSizes = true %}
{% endif %}
{% if attributes is not defined %}
{% set attributes = {} %}
{% endif %}
{% if attributes == null %}
{% set attributes = { 'loading': 'lazy' } %}
{% else %}
{% if loadingLazy is not defined %}
{% set attributes = attributes|merge({ 'loading': 'lazy' }) %}
{% endif %}
{% endif %}
{% if attributes.alt is not defined and media.translated.alt is defined %}
{% set attributes = attributes|merge({'alt': media.translated.alt}) %}
{% endif %}
{% if attributes.title is not defined and media.translated.title is defined %}
{% set attributes = attributes|merge({'title': media.translated.title}) %}
{% endif %}
{# uses cms block column count and all available thumbnails to determine the correct image size for the current viewport #}
{% if media.thumbnails|length > 0 %}
{% if autoColumnSizes is not defined and columns is defined and sizes is not defined %}
{# set image size for every viewport #}
{% set sizes = {
'xs': (theme_config('breakpoint-sm') - 1) ~'px',
'sm': (theme_config('breakpoint-md')- 1) ~'px',
'md': (theme_config('breakpoint-lg') - 1) ~'px',
'lg': (theme_config('breakpoint-xl') - 1) ~'px'
} %}
{# set image size for largest viewport depending on the cms block sizing mode (boxed or full-width) #}
{% if layout == 'full-width' %}
{% set container = 100 %}
{% set sizes = sizes|merge({ 'xl': (container / columns)|round(0, 'ceil') ~'vw'}) %}
{% else %}
{% set container = 489 %}
{% set sizes = sizes|merge({ 'sm': (container)|round(0, 'ceil') ~'px'}) %}
{% set container = 681 %}
{% set sizes = sizes|merge({ 'md': (container)|round(0, 'ceil') ~'px'}) %}
{% set container = 749 - 30 %}
{% set sizes = sizes|merge({ 'lg': (container / columns)|round(0, 'ceil') ~'px'}) %}
{% set container = 1136 - 30 %}
{% set sizes = sizes|merge({ 'xl': (container / columns)|round(0, 'ceil') ~'px'}) %}
{% endif %}
{% elseif layout == "product-single" %}
{# set image size for every viewport #}
{% set sizes = {
'xs': '90px',
'sm': '90px',
'md': '200px',
'lg': '200px',
'xl': '200px'
} %}
{% endif %}
{% set thumbnails = media.thumbnails|sort|reverse %}
{# generate srcset with all available thumbnails #}
{% if layout == "product-single" %}
{% set srcsetValue %}{% apply spaceless %}
{% for thumbnail in thumbnails %}
{{ thumbnail.url | sw_encode_url }}
{% if thumbnail.width == 1172 %}
1172w
{% if not loop.last %}, {% endif %}
{% elseif thumbnail.width == 744 %}
744w
{% if not loop.last %}, {% endif %}
{% elseif thumbnail.width == 586 %}
586w
{% if not loop.last %}, {% endif %}
{% elseif thumbnail.width == 480 %}
480w
{% if not loop.last %}, {% endif %}
{% elseif thumbnail.width == 372 %}
372w
{% if not loop.last %}, {% endif %}
{% elseif thumbnail.width == 240 %}
240w
{% if not loop.last %}, {% endif %}
{% elseif thumbnail.width == 170 %}
170w
{% if not loop.last %}, {% endif %}
{% else %}
{% if not loop.last %}, {% endif %}
{% endif %}
{% endfor %}
{% endapply %}{% endset %}
{% else %}
{% set srcsetValue %}{% apply spaceless %}
{# {{ media|sw_encode_media_url }} {{ thumbnails|first.width + 1 }}w, {% for thumbnail in thumbnails %}{{ thumbnail.url | sw_encode_url }} {{ thumbnail.width }}w{% if not loop.last %}, {% endif %}{% endfor %} #}
{% for thumbnail in thumbnails %}{{ thumbnail.url | sw_encode_url }} {{ thumbnail.width }}w{% if not loop.last %}, {% endif %}{% endfor %}
{% endapply %}{% endset %}
{% endif %}
{# generate sizes #}
{% set sizesValue %}{% apply spaceless %}
{% if layout == "product-single" %}
{% set sizeFallback = "240px" %}
{% else %}
{% set sizeFallback = "calc(100vw - 30px)" %}
{% endif %}
{# set largest size depending on column count of cms block #}
{% if autoColumnSizes and columns %}
{% set sizeFallback = (sizeFallback / columns)|round(0, 'ceil') %}
{% endif %}
{% set breakpoint = {
'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 %}
{% 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 }}
{% endapply %}{% endset %}
{% endif %}
<img {% if load %}
{# src="{{ media|sw_encode_media_url }}" #}
{% if layout == "product-single" %}
src="{{ media|sw_encode_media_url }}"
{% else %}
src="{% if thumbnails|last.url %}{{ thumbnails|last.url }}{% else %}{{ media|sw_encode_media_url }}{% endif %}"
{% endif %}
{% else %}
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="
{# data-src="{{ media|sw_encode_media_url }}" #}
data-src="{% if thumbnails|last.url %}{{ thumbnails|last.url }}{% else %}{{ media|sw_encode_media_url }}{% endif %}"
{% endif %}
{% if media.thumbnails|length > 0 %}
{% if load %}srcset="{{ srcsetValue }}" {% else %}data-srcset="{{ srcsetValue }}" {% endif %}
{% if load %}
{% if layout == "product-single" %}
sizes="(max-width: 767px) 240px, 586px"
{% else %}
{% if sizes['default'] %}
sizes="{{ sizes['default'] }}"
{% elseif sizes|length > 0 %}
sizes="{{ sizesValue }}"
{% endif %}
{% endif %}
{% else %}
{% if layout == "product-single" %}
data-sizes="(max-width: 767px) 83px, 201px"
{% else %}
{% if sizes['default'] %}
data-sizes="{{ sizes['default'] }}"
{% elseif sizes|length > 0 %}
data-sizes="{{ sizesValue }}"
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% for key, value in attributes %}{% if value != '' %} {{ key }}="{{ value }}"{% endif %}{% endfor %}
/>