custom/plugins/WeedesignPageSpeed/src/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 config('WeedesignPageSpeed.config.lazy') %}
  20.         {% if attributes.class %}
  21.             {% set attributes = attributes|merge({'class': 'weedesign-lazy weedesign-lazy-hidden weedesign-lazy-effect ' ~ attributes.class}) %}
  22.         {% else %}
  23.             {% set attributes = attributes|merge({'class': 'weedesign-lazy weedesign-lazy-hidden weedesign-lazy-effect'}) %}
  24.         {% endif %}
  25.     {% endif %}
  26.     {% if attributes.alt is not defined and media.translated.alt is defined %}
  27.         {% set attributes = attributes|merge({'alt': media.translated.alt}) %}
  28.     {% endif %}
  29.     {% if attributes.title is not defined and media.translated.title is defined %}
  30.         {% set attributes = attributes|merge({'title': media.translated.title}) %}
  31.     {% endif %}
  32.     {# uses cms block column count and all available thumbnails to determine the correct image size for the current viewport #}
  33.     {% if media.thumbnails|length > 0 %}
  34.         {% if autoColumnSizes and columns and sizes is not defined %}
  35.             {# set image size for every viewport #}
  36.             {% set sizes = {
  37.                 'xs': (theme_config('breakpoint.sm') - 1) ~'px',
  38.                 'sm': (theme_config('breakpoint.md') - 1) ~'px',
  39.                 'md': ((theme_config('breakpoint.lg') - 1) / columns)|round(0, 'ceil') ~'px',
  40.                 'lg': ((theme_config('breakpoint.xl') - 1) / columns)|round(0, 'ceil') ~'px'
  41.             } %}
  42.             {# set image size for largest viewport depending on the cms block sizing mode (boxed or full-width) #}
  43.             {% if layout == 'full-width' %}
  44.                 {% set container = 100 %}
  45.                 {% set sizes = sizes|merge({ 'xl': (container / columns)|round(0, 'ceil') ~'vw'}) %}
  46.             {% else %}
  47.                 {% set container = 1360 %}
  48.                 {% set sizes = sizes|merge({ 'xl': (container / columns)|round(0, 'ceil') ~'px'}) %}
  49.             {% endif %}
  50.         {% endif %}
  51.         {% set thumbnails = media.thumbnails|sort|reverse %}
  52.         {# generate srcset with all available thumbnails #}
  53.         {% set srcsetValue %}{% apply spaceless %}
  54.             {% if config('WeedesignPageSpeed.config.webp') %}
  55.                 {% if loadOriginalImage %}
  56.                     {{ media | weedesign_pagespeed_webp_url_media }} {{ thumbnails|first.width + 1 }}w, 
  57.                 {% endif %}
  58.                 {% for thumbnail in thumbnails %}
  59.                     {{ thumbnail | weedesign_pagespeed_webp_url_thumbnail }} {{ thumbnail.width }}w{% if not loop.last %}, {% endif %}
  60.                 {% endfor %}
  61.             {% else %}
  62.                 {% if loadOriginalImage %}
  63.                     {{ media | sw_encode_media_url }} {{ thumbnails|first.width + 1 }}w, 
  64.                 {% endif %}
  65.                 {% for thumbnail in thumbnails %}
  66.                     {{ thumbnail.url | sw_encode_url }} {{ thumbnail.width }}w{% if not loop.last %}, {% endif %}
  67.                 {% endfor %}
  68.             {% endif %}
  69.         {% endapply %}{% endset %}
  70.         {# generate sizes #}
  71.         {% set sizesValue %}{% apply spaceless %}
  72.             {% set sizeFallback = 100 %}
  73.             {# set largest size depending on column count of cms block #}
  74.             {% if autoColumnSizes and columns %}
  75.                 {% set sizeFallback = (sizeFallback / columns)|round(0, 'ceil') %}
  76.             {% endif %}
  77.             {% set breakpoint = {
  78.                 'xs': theme_config('breakpoint.xs'),
  79.                 'sm': theme_config('breakpoint.sm'),
  80.                 'md': theme_config('breakpoint.md'),
  81.                 'lg': theme_config('breakpoint.lg'),
  82.                 'xl': theme_config('breakpoint.xl')
  83.             } %}
  84.             {% if thumbnails|first.width > breakpoint|reverse|first %}
  85.                 {# @deprecated tag:v6.5.0 - Variable `maxWidth` and parent condition will be removed #}
  86.                 {% set maxWidth = thumbnails|first.width %}
  87.             {% endif %}
  88.             {% for key, value in breakpoint|reverse %}(min-width: {{ value }}px) {{ sizes[key] }}{% if not loop.last %}, {% endif %}{% endfor %}, {{ sizeFallback }}vw
  89.         {% endapply %}{% endset %}
  90.     {% endif %}
  91.     {% block thumbnail_utility_img %}
  92.         {% if config('WeedesignPageSpeed.config.lazy') %}
  93.             {% if config('WeedesignPageSpeed.config.webp') %}
  94.                 <img 
  95.                     src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
  96.                     data-src="{{ media|weedesign_pagespeed_webp_url_media }}" 
  97.                     data-effect="{{ config('WeedesignPageSpeed.config.lazyEffect') }}"
  98.                     {% if config('WeedesignPageSpeed.config.fallback') %}
  99.                         data-fallback="{{ media.url|weedesign_pagespeed_webp_url_nope }}"
  100.                     {% endif %}
  101.                     {% if media.thumbnails|length > 0 %}
  102.                         data-srcset="{{ srcsetValue }}" 
  103.                         {% if sizes['default'] %}
  104.                             sizes="{{ sizes['default'] }}"
  105.                         {% elseif sizes|length > 0 %}
  106.                             sizes="{{ sizesValue }}"
  107.                         {% endif %}
  108.                     {% else %}
  109.                         data-srcset="{{ media|weedesign_pagespeed_webp_url_media }}" 
  110.                     {% endif %}
  111.                     {% for key, value in attributes %}
  112.                         {% if value != '' %} 
  113.                             {% if key != 'itemprop' %} 
  114.                                 {{ key }}="{{ value }}"
  115.                             {% endif %}
  116.                         {% endif %}
  117.                     {% endfor %}
  118.                 />
  119.             {% else %}
  120.                 <img 
  121.                     src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
  122.                     data-src="{{ media|sw_encode_media_url }}" 
  123.                     data-effect="{{ config('WeedesignPageSpeed.config.lazyEffect') }}"
  124.                     {% if media.thumbnails|length > 0 %}
  125.                         data-srcset="{{ srcsetValue }}" 
  126.                         {% if sizes['default'] %}
  127.                             sizes="{{ sizes['default'] }}"
  128.                         {% elseif sizes|length > 0 %}
  129.                             sizes="{{ sizesValue }}"
  130.                         {% endif %}
  131.                     {% endif %}
  132.                     {% for key, value in attributes %}
  133.                         {% if value != '' %} 
  134.                             {% if key != 'itemprop' %} 
  135.                                 {{ key }}="{{ value }}"
  136.                             {% endif %}
  137.                         {% endif %}
  138.                     {% endfor %}
  139.                 />
  140.             {% endif %}
  141.             {% set noscript = false %}
  142.             {% for key, value in attributes %}
  143.                 {% if value != '' %} 
  144.                     {% if key == 'itemprop' %} 
  145.                         {% set noscript = true %}
  146.                     {% endif %}
  147.                 {% endif %}
  148.             {% endfor %}
  149.             {% if noscript == true %} 
  150.                 <noscript>
  151.                     <img 
  152.                         src="{{ media|sw_encode_media_url }}"
  153.                         {% if media.thumbnails|length > 0 %}
  154.                             {% if load %}
  155.                                 srcset="{{ srcsetValue }}" 
  156.                             {% else %}
  157.                                 data-srcset="{{ srcsetValue }}" 
  158.                             {% endif %}
  159.                             {% if sizes['default'] %}
  160.                                 sizes="{{ sizes['default'] }}"
  161.                             {% elseif sizes|length > 0 %}
  162.                                 sizes="{{ sizesValue }}"
  163.                             {% endif %}
  164.                         {% endif %}
  165.                         {% for key, value in attributes %}
  166.                             {% if value != '' %} 
  167.                                 {{ key }}="{{ value }}"
  168.                             {% endif %}
  169.                         {% endfor %}
  170.                     />
  171.                 </noscript>
  172.             {% endif %}
  173.         {% else %}
  174.             {% if config('WeedesignPageSpeed.config.webp') %}
  175.                 <img 
  176.                     {% if load %}
  177.                         src="{{ media|weedesign_pagespeed_webp_url_media }}"
  178.                     {% else %}
  179.                         data-src="{{ media|weedesign_pagespeed_webp_url_media }}" 
  180.                     {% endif %}
  181.                     {% if config('WeedesignPageSpeed.config.fallback') %}
  182.                         data-fallback="{{ media.url|weedesign_pagespeed_webp_url_nope }}"
  183.                     {% endif %}
  184.                     {% if media.thumbnails|length > 0 %}
  185.                         {% if load %}
  186.                             srcset="{{ srcsetValue }}" 
  187.                         {% else %}
  188.                             data-srcset="{{ srcsetValue }}" 
  189.                         {% endif %}
  190.                         {% if sizes['default'] %}
  191.                             sizes="{{ sizes['default'] }}"
  192.                         {% elseif sizes|length > 0 %}
  193.                             sizes="{{ sizesValue }}"
  194.                         {% endif %}
  195.                     {% endif %}
  196.                     {% for key, value in attributes %}
  197.                         {% if value != '' %} 
  198.                             {{ key }}="{{ value }}"
  199.                         {% endif %}
  200.                     {% endfor %}
  201.                 />
  202.             {% else %}
  203.                 <img 
  204.                     {% if load %}
  205.                         src="{{ media|sw_encode_media_url }}"
  206.                     {% else %}
  207.                         data-src="{{ media|sw_encode_media_url }}" 
  208.                     {% endif %}
  209.                     {% if media.thumbnails|length > 0 %}
  210.                         {% if load %}
  211.                             srcset="{{ srcsetValue }}" 
  212.                         {% else %}
  213.                             data-srcset="{{ srcsetValue }}" 
  214.                         {% endif %}
  215.                         {% if sizes['default'] %}
  216.                             sizes="{{ sizes['default'] }}"
  217.                         {% elseif sizes|length > 0 %}
  218.                             sizes="{{ sizesValue }}"
  219.                         {% endif %}
  220.                     {% endif %}
  221.                     {% for key, value in attributes %}
  222.                         {% if value != '' %} 
  223.                             {{ key }}="{{ value }}"
  224.                         {% endif %}
  225.                     {% endfor %}
  226.                 />
  227.             {% endif %}
  228.             
  229.         {% endif %}
  230.     {% endblock %}
  231. {% endblock %}