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

Open in your IDE?
  1. {% if attributes is not defined %}
  2.     {% set attributes = {} %}
  3. {% endif %}
  4. {# activate load per default. If it is not activated only a data-src is set instead of the src tag. #}
  5. {% if load is not defined %}
  6.     {% set load = true %}
  7. {% endif %}
  8. {# uses cms block column count and all available thumbnails to determine the correct image size for the current viewport #}
  9. {% if media.thumbnails|length > 0 %}
  10.     {% if columns and sizes is not defined %}
  11.         {# set image size for every viewport #}
  12.         {% set sizes = {
  13.             'xs': (shopware.theme.breakpoint.sm - 1) ~'px',
  14.             'sm': (shopware.theme.breakpoint.md - 1) ~'px',
  15.             'md': ((shopware.theme.breakpoint.lg - 1) / columns)|round(0, 'ceil') ~'px',
  16.             'lg': ((shopware.theme.breakpoint.xl - 1) / columns)|round(0, 'ceil') ~'px'
  17.         } %}
  18.         {# set image size for largest viewport depending on the cms block sizing mode (boxed or full-width) #}
  19.         {% if layout == 'full-width' %}
  20.             {% set container = 100 %}
  21.             {% set sizes = sizes|merge({ 'xl': (container / columns)|round(0, 'ceil') ~'vw'}) %}
  22.         {% else %}
  23.             {% set defaultContainerMaxSize = shopware.config.FroshPlatformThumbnailProcessor.config.DefaultContainerMaxSize %}
  24.             {% if defaultContainerMaxSize is defined %}
  25.                 {% set container = defaultContainerMaxSize %}
  26.             {% else %}
  27.                 {% set container = 1360 %}
  28.             {% endif %}
  29.             {% set sizes = sizes|merge({ 'xl': (container / columns)|round(0, 'ceil') ~'px'}) %}
  30.         {% endif %}
  31.     {% endif %}
  32.     {% set thumbnails = media.thumbnails|filter((v) => v.width <= media.metaData.width and v.height <= media.metaData.height)|sort|reverse %}
  33.     {# generate srcset with all available thumbnails #}
  34.     {% set srcsetValue %}{% apply spaceless %}
  35.         {{ 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 %}
  36.     {% endapply %}{% endset %}
  37.     {# generate sizes #}
  38.     {% set sizesValue %}{% apply spaceless %}
  39.         {% set sizeFallback = 100 %}
  40.         {# set largest size depending on column count of cms block #}
  41.         {% if columns %}
  42.             {% set sizeFallback = (sizeFallback / columns)|round(0, 'ceil') %}
  43.         {% endif %}
  44.         {% for key, value in shopware.theme.breakpoint|reverse %}(min-width: {{ value }}px) {{ sizes[key] }}{% if not loop.last %}, {% endif %}{% endfor %}, {{ sizeFallback }}vw
  45.     {% endapply %}{% endset %}
  46. {% endif %}
  47. {% if load is same as(true) %}
  48.     {% if attributes.class %}
  49.         {% set attributes = attributes|merge({'class': 'lazyload ' ~ attributes.class}) %}
  50.     {% else %}
  51.         {% set attributes = attributes|merge({'class': 'lazyload'}) %}
  52.     {% endif %}
  53.     <img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
  54.         data-src="{{ media|sw_encode_media_url }}"
  55.         {% if media.thumbnails|length > 1 %}
  56.             data-srcset="{{ srcsetValue }}"
  57.             data-sizes="auto"
  58.         {% endif %}
  59.         {% for key, value in attributes %} {{ key }}="{{ value }}"{% endfor %}
  60.     />
  61. {% else %}
  62.     <img data-src="{{ media|sw_encode_media_url }}"
  63.         {% if media.thumbnails|length > 1 %}
  64.             data-srcset="{{ srcsetValue }}"
  65.             {% if sizes['default'] %}
  66.             sizes="{{ sizes['default'] }}"
  67.             {% elseif sizes|length > 0 %}
  68.             sizes="{{ sizesValue }}"
  69.             {% endif %}
  70.         {% endif %}
  71.         {% for key, value in attributes %} {{ key }}="{{ value }}"{% endfor %}
  72.     />
  73. {% endif %}