custom/plugins/FroshLazySizes/src/Resources/views/storefront/utilities/thumbnail-lazysize.html.twig line 1

  1. {% block thumbnail_utility_lazysize %}{% apply spaceless %}
  2.     {% if attributes is not defined %}
  3.         {% set attributes = {} %}
  4.     {% endif %}
  5.     {% if attributes.class %}
  6.         {% set attributes = attributes|merge({'class': 'frosh-proc lazyload ' ~ attributes.class}) %}
  7.     {% else %}
  8.         {% set attributes = attributes|merge({'class': 'frosh-proc lazyload'}) %}
  9.     {% endif %}
  10.     {% if attributes.alt is not defined and media.translated.alt is defined %}
  11.         {% set attributes = attributes|merge({'alt': media.translated.alt}) %}
  12.     {% endif %}
  13.     {% if attributes.title is not defined and media.translated.title is defined %}
  14.         {% set attributes = attributes|merge({'title': media.translated.title}) %}
  15.     {% endif %}
  16.     {% set metaProportion = media.metaData %}
  17.     {% if media.thumbnails|length > 0 %}
  18.         {% set thumbnails = media.thumbnails|filter((v) => v.width <= metaProportion.width)|sort((a, b) => a.width <=> b.width)|reverse %}
  19.         {% if thumbnails %}
  20.             {# generate srcset with all available thumbnails #}
  21.             {% set srcsetValue %}{% apply spaceless %}
  22.                 {{ media.url|frosh_encode_url }} {{ thumbnails|first.width + 1 }}w, {% for thumbnail in thumbnails %}{{ thumbnail.url|frosh_encode_url }} {{ thumbnail.width }}w{% if not loop.last %}, {% endif %}{% endfor %}
  23.             {% endapply %}{% endset %}
  24.         {% endif %}
  25.     {% endif %}
  26.     {% set ratio = metaProportion.width / metaProportion.height|default(1) %}
  27.     {% set inlineStyle = "aspect-ratio:" ~ ratio ~ ";" %}
  28.     {% if attributes.style %}
  29.         {% set attributes = attributes|merge({'style': inlineStyle ~ attributes.style}) %}
  30.     {% else %}
  31.         {% set attributes = attributes|merge({'style': inlineStyle}) %}
  32.     {% endif %}
  33.     {% set parentFit = parentFit ?? attributes['data-object-fit'] ?? false %}
  34.     {% if not parentFit and 'product-image' in attributes.class and 'is-standard' in attributes.class %}
  35.         {% set parentFit = 'contain' %}
  36.     {% endif %}
  37.     {% if not config('FroshLazySizes.config.UseAdvancedRatio') %}
  38.         {% set ratio = max(1, ratio) %}
  39.     {% endif %}
  40.     {% block thumbnail_utility_img %}
  41.         {% if src is not defined %}
  42.             {% set src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==' %}
  43.         {% endif %}
  44.         <img src="{{ src }}"
  45.             data-src="{{ media.url|frosh_encode_url }}"
  46.             {% if srcsetValue %}
  47.                 data-srcset="{{ srcsetValue }}"
  48.                 data-sizes="auto"
  49.                 data-aspectratio="{{ ratio }}"
  50.                 {% if parentFit %}data-parent-fit="{{ parentFit }}"{% endif %}
  51.             {% endif %}
  52.             {% for key, value in attributes %}
  53.                 {{ key }}="{{ value }}"
  54.                 {% if key == 'itemprop' %}
  55.                     content="{{ media.url|frosh_encode_url }}"
  56.                 {% endif %}
  57.             {% endfor %}
  58.         />
  59.     {% endblock %}
  60. {% endapply %}{% endblock %}