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

Open in your IDE?
  1. {% set foxDomainReplace = {} %}
  2. {% if config('FuexcImageCDN.config.cdnUrl') and config('FuexcImageCDN.config.rewriteThumbnails') %}
  3.     {% set foxDomainReplace = {
  4.         "https://cdn.shopware.store": config('FuexcImageCDN.config.cdnUrl')|trim('/')
  5.     } %}
  6.     {% for salesChannelDomain in context.salesChannel.domains %}
  7.         {% set foxDomain = salesChannelDomain.url|split('//') %}
  8.         {% if foxDomain|length == 1 %}
  9.             {% set foxDomain = "#{(foxDomain[0]|split('/')[0])}" %}
  10.         {% elseif foxDomain|length == 2 %}
  11.             {% set foxDomain = "#{foxDomain[0]}//#{(foxDomain[1]|split('/')[0])}" %}
  12.         {% endif %}
  13.         {% set foxDomainReplace = foxDomainReplace|merge({
  14.             (foxDomain): config('FuexcImageCDN.config.cdnUrl')|trim('/')
  15.         }) %}
  16.     {% endfor %}
  17. {% endif %}
  18. {# allow the loading Stragy to be overridden from twig #}
  19. {% if loadingStrategy is not defined %}
  20.     {% set loadingStrategy = "eager" %}
  21.     {% if config('FuexcImageCDN.config.lazyLoadImages') %}
  22.         {% set loadingStrategy = "lazy" %}
  23.     {% endif %}
  24. {% endif %}
  25. {# TODO: @zenit - check on sw update #}
  26. {# activate load per default. If it is not activated only a data-src is set instead of the src tag. #}
  27. {% if load is not defined %}
  28.     {% set load = true %}
  29. {% endif %}
  30. {# By default no original image will be loaded as soon as thumbnails are available. #}
  31. {# When set to true the orginal image will be loaded when the viewport is greater than the largest available thumbnail. #}
  32. {% if loadOriginalImage is not defined %}
  33.     {% set loadOriginalImage = false %}
  34. {% endif %}
  35. {# By default the srcset sizes will be calculated automatically if `columns` are present and no `sizes` are configured. #}
  36. {# When set to false the sizes attribute will not be generated automatically. #}
  37. {% if autoColumnSizes is not defined %}
  38.     {% set autoColumnSizes = true %}
  39. {% endif %}
  40. {% if attributes is not defined %}
  41.     {% set attributes = {} %}
  42. {% endif %}
  43. {% if attributes.alt is not defined and media.translated.alt is defined %}
  44.     {% set attributes = attributes|merge({'alt': media.translated.alt}) %}
  45. {% endif %}
  46. {% if attributes.title is not defined and media.translated.title is defined %}
  47.     {% set attributes = attributes|merge({'title': media.translated.title}) %}
  48. {% endif %}
  49. {# uses cms block column count and all available thumbnails to determine the correct image size for the current viewport #}
  50. {% if media.thumbnails|length > 0 %}
  51.     {% set sizes = {
  52.         'sm': theme_config('breakpoint.sm') ~'px',
  53.         'md': theme_config('breakpoint.md') ~'px',
  54.         'lg': theme_config('breakpoint.lg') ~'px',
  55.         'xl': theme_config('breakpoint.xl') ~'px',
  56.         'xxl': "1900px",
  57.    } %}
  58.     {% set thumbnails = media.thumbnails|sort|reverse %}
  59.     {# generate srcset with all available thumbnails #}
  60.     {% set srcsetValue %}{% apply spaceless %}
  61.         {% if loadOriginalImage %}{{ media|sw_encode_media_url }} {{ thumbnails|first.width + 1 }}w, {% endif %}{% for thumbnail in thumbnails|reverse %}{{ thumbnail.url | sw_encode_url }} {{ thumbnail.width }}w{% if not loop.last %}, {% endif %}{% endfor %}
  62.     {% endapply %}{% endset %}
  63.     {# generate sizes #}
  64.     {% set sizesValue %}{% apply spaceless %}
  65.         {% set breakpoint = {
  66.             'sm': theme_config('breakpoint.sm'),
  67.             'md': theme_config('breakpoint.md'),
  68.             'lg': theme_config('breakpoint.lg'),
  69.             'xl': theme_config('breakpoint.xl'),
  70.             'xxl': "1900"
  71.         } %}
  72.         {% if thumbnails|first.width > breakpoint|reverse|first %}
  73.             {# @deprecated @zenit tag:v3.1.0 - Variable `maxWidth` and parent condition will be removed #}
  74.             {% set maxWidth = thumbnails|first.width %}
  75.         {% endif %}
  76.         {% for key, value in breakpoint|reverse %}(min-width: {{ value }}px) {{ sizes[key] }}{% if not loop.last %}, {% endif %}{% endfor %}
  77.     {% endapply %}{% endset %}
  78. {% endif %}
  79. {% if foxDomainReplace is not defined %}
  80.     {# Fallback for other plugins replacing the thumbnail_utility block and not calling parent #}
  81.     {% set foxDomainReplace = {} %}
  82. {% endif %}
  83. <img loading="{% if attributes.loading %}{{ attributes.loading }}{% else %}{{ loadingStrategy }}{% endif %}" {% if load %}src="{{ media|sw_encode_media_url|replace(foxDomainReplace) }}" {% else %}data-src="{{ media|sw_encode_media_url|replace(foxDomainReplace) }}" {% endif %}
  84.     {% if media.thumbnails|length > 0 %}
  85.         {% if load %}srcset="{{ srcsetValue|replace(foxDomainReplace) }}" {% else %}data-srcset="{{ srcsetValue|replace(foxDomainReplace) }}" {% endif %}
  86.         {% if sizes['default'] %}
  87.         sizes="{{ sizes['default'] }}"
  88.         {% elseif sizes|length > 0 %}
  89.         sizes="{{ sizesValue }}"
  90.         {% endif %}
  91.     {% endif %}
  92.     {% for key, value in attributes %}{% if value != '' %} {{ key }}="{{ value }}"{% endif %}{% endfor %}
  93. />