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

Open in your IDE?
  1. {# TODO: @zenit check on sw update #}
  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.             {# ... add layout container width #}
  41.             {% set container = theme_config("zen-layout-container-width") ?: 1400 %}
  42.             {% set sizes = sizes|merge({ 'xl': (container / columns)|round(0, 'ceil') ~'px'}) %}
  43.         {% endif %}
  44.     {% endif %}
  45.     {% set thumbnails = media.thumbnails|sort|reverse %}
  46.     {# generate srcset with all available thumbnails #}
  47.     {% set srcsetValue %}{% apply spaceless %}
  48.         {% 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 %}
  49.     {% endapply %}{% endset %}
  50.     {# generate sizes #}
  51.     {% set sizesValue %}{% apply spaceless %}
  52.         {% set sizeFallback = 100 %}
  53.         {# set largest size depending on column count of cms block #}
  54.         {% if autoColumnSizes and columns %}
  55.             {% set sizeFallback = (sizeFallback / columns)|round(0, 'ceil') %}
  56.         {% endif %}
  57.         {% set breakpoint = {
  58.             'xs': theme_config('breakpoint.xs'),
  59.             'sm': theme_config('breakpoint.sm'),
  60.             'md': theme_config('breakpoint.md'),
  61.             'lg': theme_config('breakpoint.lg'),
  62.             'xl': theme_config('breakpoint.xl')
  63.         } %}
  64.         {% if thumbnails|first.width > breakpoint|reverse|first %}
  65.             {# @deprecated tag:v6.5.0 - Variable `maxWidth` and parent condition will be removed #}
  66.             {% set maxWidth = thumbnails|first.width %}
  67.         {% endif %}
  68.         {% for key, value in breakpoint|reverse %}(min-width: {{ value }}px) {{ sizes[key] }}{% if not loop.last %}, {% endif %}{% endfor %}, {{ sizeFallback }}vw
  69.     {% endapply %}{% endset %}
  70. {% endif %}
  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. />