custom/plugins/NextagTheme/src/Resources/views/storefront/utilities/thumbnail.html.twig line 1

Open in your IDE?
  1. {# activate load per default. If it is not activated only a data-src is set instead of the src tag. #}
  2. {% if load is not defined %}
  3.     {% set load = true %}
  4. {% endif %}
  5. {# By default no original image will be loaded as soon as thumbnails are available. #}
  6. {# When set to true the orginal image will be loaded when the viewport is greater than the largest available thumbnail. #}
  7. {% if loadOriginalImage is not defined %}
  8.     {% set loadOriginalImage = false %}
  9. {% endif %}
  10. {# By default the srcset sizes will be calculated automatically if `columns` are present and no `sizes` are configured. #}
  11. {# When set to false the sizes attribute will not be generated automatically. #}
  12. {% if autoColumnSizes %}
  13.     {% set autoColumnSizes = true %}
  14. {% endif %}
  15. {% if attributes is not defined %}
  16.     {% set attributes = {} %}
  17. {% endif %}
  18. {% if attributes == null %}
  19.     {% set attributes = { 'loading': 'lazy' } %}
  20. {% else %}
  21.     {% if loadingLazy is not defined %}
  22.         {% set attributes = attributes|merge({ 'loading': 'lazy' }) %}
  23.     {% endif %}
  24. {% endif %}
  25. {% if attributes.alt is not defined and media.translated.alt is defined %}
  26.     {% set attributes = attributes|merge({'alt': media.translated.alt}) %}
  27. {% endif %}
  28. {% if attributes.title is not defined and media.translated.title is defined %}
  29.     {% set attributes = attributes|merge({'title': media.translated.title}) %}
  30. {% endif %}
  31. {# uses cms block column count and all available thumbnails to determine the correct image size for the current viewport #}
  32. {% if media.thumbnails|length > 0 %}
  33.     {% if autoColumnSizes is not defined and columns is defined and sizes is not defined %}
  34.         {# set image size for every viewport #}
  35.         {% set sizes = {
  36.             'xs': (theme_config('breakpoint-sm') - 1) ~'px',
  37.             'sm': (theme_config('breakpoint-md')- 1) ~'px',
  38.             'md': (theme_config('breakpoint-lg') - 1) ~'px',
  39.             'lg': (theme_config('breakpoint-xl') - 1) ~'px'
  40.         } %}      
  41.         {# set image size for largest viewport depending on the cms block sizing mode (boxed or full-width) #}
  42.         {% if layout == 'full-width' %}
  43.             {% set container = 100 %}
  44.             {% set sizes = sizes|merge({ 'xl': (container / columns)|round(0, 'ceil') ~'vw'}) %}
  45.         {% else %}
  46.             {% set container = 489 %}
  47.             {% set sizes = sizes|merge({ 'sm': (container)|round(0, 'ceil') ~'px'}) %}
  48.             {% set container = 681 %}
  49.             {% set sizes = sizes|merge({ 'md': (container)|round(0, 'ceil') ~'px'}) %}
  50.             {% set container = 749 - 30 %}
  51.             {% set sizes = sizes|merge({ 'lg': (container / columns)|round(0, 'ceil') ~'px'}) %}
  52.             {% set container = 1136 - 30 %}
  53.             {% set sizes = sizes|merge({ 'xl': (container / columns)|round(0, 'ceil') ~'px'}) %}
  54.         {% endif %}
  55.     
  56.     {% elseif layout == "product-single" %}
  57.         {# set image size for every viewport #}
  58.         {% set sizes = {
  59.             'xs': '90px',
  60.             'sm': '90px',
  61.             'md': '200px',
  62.             'lg': '200px',
  63.             'xl': '200px'
  64.         } %}
  65.     {% endif %}
  66.     
  67.     {% set thumbnails = media.thumbnails|sort|reverse %}
  68.     {# generate srcset with all available thumbnails #}
  69.     {% if layout == "product-single" %}
  70.         {% set srcsetValue %}{% apply spaceless %}
  71.             {% for thumbnail in thumbnails %}
  72.                 {{ thumbnail.url | sw_encode_url }} 
  73.                 {% if thumbnail.width == 1172 %}
  74.                     1172w
  75.                     {% if not loop.last %}, {% endif %}
  76.                 {% elseif thumbnail.width == 744 %}
  77.                     744w
  78.                     {% if not loop.last %}, {% endif %}
  79.                 {% elseif thumbnail.width == 586 %}
  80.                     586w
  81.                     {% if not loop.last %}, {% endif %}
  82.                 {% elseif thumbnail.width == 480 %}
  83.                     480w
  84.                     {% if not loop.last %}, {% endif %}
  85.                 {% elseif thumbnail.width == 372 %}
  86.                     372w
  87.                     {% if not loop.last %}, {% endif %}
  88.                 {% elseif thumbnail.width == 240 %}
  89.                     240w
  90.                     {% if not loop.last %}, {% endif %}
  91.                 {% elseif thumbnail.width == 170 %}
  92.                     170w
  93.                     {% if not loop.last %}, {% endif %}
  94.                 {% else %}
  95.                     {% if not loop.last %}, {% endif %}
  96.                 {% endif %}
  97.             {% endfor %}
  98.         {% endapply %}{% endset %}
  99.     {% else %}
  100.         {% set srcsetValue %}{% apply spaceless %}
  101.             {# {{ 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 %} #}
  102.             {% for thumbnail in thumbnails %}{{ thumbnail.url | sw_encode_url }} {{ thumbnail.width }}w{% if not loop.last %}, {% endif %}{% endfor %}
  103.         {% endapply %}{% endset %}
  104.     {% endif %}
  105.     {# generate sizes #}
  106.     {% set sizesValue %}{% apply spaceless %}
  107.             {% if layout == "product-single" %}
  108.                 {% set sizeFallback = "240px" %}
  109.             {% else %}
  110.                 {% set sizeFallback = "calc(100vw - 30px)" %}
  111.             {% endif %}
  112.             {# set largest size depending on column count of cms block #}
  113.             {% if autoColumnSizes and columns %}
  114.                 {% set sizeFallback = (sizeFallback / columns)|round(0, 'ceil') %}
  115.             {% endif %}
  116.             {% set breakpoint = {
  117.                 'sm': theme_config('breakpoint-sm'),
  118.                 'md': theme_config('breakpoint-md'),
  119.                 'lg': theme_config('breakpoint-lg'),
  120.                 'xl': theme_config('breakpoint-xl')
  121.             } %}
  122.             {% if thumbnails|first.width > breakpoint|reverse|first %}
  123.                 {% set maxWidth = thumbnails|first.width %}
  124.             {% endif %}
  125.             {% for key, value in breakpoint|reverse %}(min-width: {{ value }}px) {{ sizes[key] }}{% if not loop.last %}, {% endif %}{% endfor %}, {{ sizeFallback }}
  126.         {% endapply %}{% endset %}
  127. {% endif %}
  128. <img {% if load %}
  129.         {# src="{{ media|sw_encode_media_url }}"  #}
  130.         {% if layout == "product-single" %}
  131.             src="{{ media|sw_encode_media_url }}"
  132.         {% else %}
  133.             src="{% if thumbnails|last.url %}{{ thumbnails|last.url }}{% else %}{{ media|sw_encode_media_url }}{% endif %}"
  134.         {% endif %}
  135.     {% else %}
  136.         src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="
  137.         {# data-src="{{ media|sw_encode_media_url }}" #}
  138.         data-src="{% if thumbnails|last.url %}{{ thumbnails|last.url }}{% else %}{{ media|sw_encode_media_url }}{% endif %}"
  139.     {% endif %}
  140.     {% if media.thumbnails|length > 0 %}
  141.         {% if load %}srcset="{{ srcsetValue }}" {% else %}data-srcset="{{ srcsetValue }}" {% endif %}
  142.         {% if load %}
  143.             {% if layout == "product-single" %}
  144.                 sizes="(max-width: 767px) 240px, 586px"
  145.             {% else %}
  146.                 {% if sizes['default'] %}
  147.                     sizes="{{ sizes['default'] }}"
  148.                 {% elseif sizes|length > 0 %}
  149.                     sizes="{{ sizesValue }}"
  150.                 {% endif %}
  151.             {% endif %}
  152.         {% else %}
  153.             {% if layout == "product-single" %}
  154.                 data-sizes="(max-width: 767px) 83px, 201px"
  155.             {% else %}
  156.                 {% if sizes['default'] %}
  157.                     data-sizes="{{ sizes['default'] }}"
  158.                 {% elseif sizes|length > 0 %}
  159.                     data-sizes="{{ sizesValue }}"
  160.                 {% endif %}
  161.             {% endif %}
  162.         {% endif %}
  163.     {% endif %}
  164.     {% for key, value in attributes %}{% if value != '' %} {{ key }}="{{ value }}"{% endif %}{% endfor %}
  165. />