vendor/shopware/storefront/Resources/views/storefront/utilities/thumbnail.html.twig line 1

Open in your IDE?
  1. {% block thumbnail_utility %}
  2. {# activate load per default. If it is not activated only a data-src is set instead of the src tag. #}
  3. {% if load is not defined %}
  4. {% set load = true %}
  5. {% endif %}
  6. {# By default no original image will be loaded as soon as thumbnails are available. #}
  7. {# When set to true the orginal image will be loaded when the viewport is greater than the largest available thumbnail. #}
  8. {% if loadOriginalImage is not defined %}
  9. {% set loadOriginalImage = false %}
  10. {% endif %}
  11. {# By default the srcset sizes will be calculated automatically if `columns` are present and no `sizes` are configured. #}
  12. {# When set to false the sizes attribute will not be generated automatically. #}
  13. {% if autoColumnSizes is not defined %}
  14. {% set autoColumnSizes = true %}
  15. {% endif %}
  16. {% if attributes is not defined %}
  17. {% set attributes = {} %}
  18. {% endif %}
  19. {% if attributes.alt is not defined and media.translated.alt is defined %}
  20. {% set attributes = attributes|merge({'alt': media.translated.alt}) %}
  21. {% endif %}
  22. {% if attributes.title is not defined and media.translated.title is defined %}
  23. {% set attributes = attributes|merge({'title': media.translated.title}) %}
  24. {% endif %}
  25. {# uses cms block column count and all available thumbnails to determine the correct image size for the current viewport #}
  26. {% if media.thumbnails|length > 0 %}
  27. {% if autoColumnSizes and columns and sizes is not defined %}
  28. {# set image size for every viewport #}
  29. {% set sizes = {
  30. 'xs': (theme_config('breakpoint.sm') - 1) ~'px',
  31. 'sm': (theme_config('breakpoint.md') - 1) ~'px',
  32. 'md': ((theme_config('breakpoint.lg') - 1) / columns)|round(0, 'ceil') ~'px',
  33. 'lg': ((theme_config('breakpoint.xl') - 1) / columns)|round(0, 'ceil') ~'px'
  34. } %}
  35. {# set image size for largest viewport depending on the cms block sizing mode (boxed or full-width) #}
  36. {% if layout == 'full-width' %}
  37. {% set container = 100 %}
  38. {% set sizes = sizes|merge({ 'xl': (container / columns)|round(0, 'ceil') ~'vw'}) %}
  39. {% else %}
  40. {% set container = 1360 %}
  41. {% set sizes = sizes|merge({ 'xl': (container / columns)|round(0, 'ceil') ~'px'}) %}
  42. {% endif %}
  43. {% endif %}
  44. {% set thumbnails = media.thumbnails|sort|reverse %}
  45. {# generate srcset with all available thumbnails #}
  46. {% set srcsetValue %}{% apply spaceless %}
  47. {% 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 %}
  48. {% endapply %}{% endset %}
  49. {# generate sizes #}
  50. {% set sizesValue %}{% apply spaceless %}
  51. {% set sizeFallback = 100 %}
  52. {# set largest size depending on column count of cms block #}
  53. {% if autoColumnSizes and columns %}
  54. {% set sizeFallback = (sizeFallback / columns)|round(0, 'ceil') %}
  55. {% endif %}
  56. {% set breakpoint = {
  57. 'xs': theme_config('breakpoint.xs'),
  58. 'sm': theme_config('breakpoint.sm'),
  59. 'md': theme_config('breakpoint.md'),
  60. 'lg': theme_config('breakpoint.lg'),
  61. 'xl': theme_config('breakpoint.xl')
  62. } %}
  63. {% if thumbnails|first.width > breakpoint|reverse|first %}
  64. {# @deprecated tag:v6.5.0 - Variable `maxWidth` and parent condition will be removed #}
  65. {% set maxWidth = thumbnails|first.width %}
  66. {% endif %}
  67. {% for key, value in breakpoint|reverse %}(min-width: {{ value }}px) {{ sizes[key] }}{% if not loop.last %}, {% endif %}{% endfor %}, {{ sizeFallback }}vw
  68. {% endapply %}{% endset %}
  69. {% endif %}
  70. {% block thumbnail_utility_img %}
  71. <img {% if load %}src="{{ media|sw_encode_media_url }}" {% else %}data-src="{{ media|sw_encode_media_url }}" {% endif %}
  72. {% if media.thumbnails|length > 0 %}
  73. {% if load %}srcset="{{ srcsetValue }}" {% else %}data-srcset="{{ srcsetValue }}" {% endif %}
  74. {% if sizes['default'] %}
  75. sizes="{{ sizes['default'] }}"
  76. {% elseif sizes|length > 0 %}
  77. sizes="{{ sizesValue }}"
  78. {% endif %}
  79. {% endif %}
  80. {% for key, value in attributes %}{% if value != '' %} {{ key }}="{{ value }}"{% endif %}{% endfor %}
  81. />
  82. {% endblock %}
  83. {% endblock %}