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

Open in your IDE?
  1. {# activate load per default. If it is not activated only a data-src is set instead of the src tag. #}
  2. {% if load is not defined %}
  3.     {% set load = true %}
  4. {% endif %}
  5. {# By default no original image will be loaded as soon as thumbnails are available. #}
  6. {# When set to true the orginal image will be loaded when the viewport is greater than the largest available thumbnail. #}
  7. {% if loadOriginalImage is not defined %}
  8.     {% set loadOriginalImage = false %}
  9. {% endif %}
  10. {# By default the srcset sizes will be calculated automatically if `columns` are present and no `sizes` are configured. #}
  11. {# When set to false the sizes attribute will not be generated automatically. #}
  12. {% if autoColumnSizes %}
  13.     {% set autoColumnSizes = true %}
  14. {% endif %}
  15. {# uses cms block column count and all available thumbnails to determine the correct image size for the current viewport #}
  16. {% if media.thumbnails|length > 0 %}
  17.     {% if autoColumnSizes and columns and sizes is not defined %}
  18.         {# set image size for every viewport #}
  19.         {% set sizes = {
  20.             'xs': (theme_config('breakpoint.sm') - 1) ~'px',
  21.             'sm': (theme_config('breakpoint.md') - 1) ~'px',
  22.             'md': ((theme_config('breakpoint.lg') - 1) / columns)|round(0, 'ceil') ~'px',
  23.             'lg': ((theme_config('breakpoint.xl') - 1) / columns)|round(0, 'ceil') ~'px'
  24.         } %}
  25.         {# set image size for largest viewport depending on the cms block sizing mode (boxed or full-width) #}
  26.         {% if layout == 'full-width' %}
  27.             {% set container = 100 %}
  28.             {% set sizes = sizes|merge({ 'xl': (container / columns)|round(0, 'ceil') ~'vw'}) %}
  29.         {% else %}
  30.             {% set container = 1360 %}
  31.             {% set sizes = sizes|merge({ 'xl': (container / columns)|round(0, 'ceil') ~'px'}) %}
  32.         {% endif %}
  33.     {% endif %}
  34.     {% set thumbnails = media.thumbnails|sort|reverse %}
  35.     {# generate srcset with all available thumbnails #}
  36.     {% set srcsetValue %}{% apply spaceless %}
  37.         {% 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 %}
  38.     {% endapply %}{% endset %}
  39.     {# generate sizes #}
  40.     {% set sizesValue %}{% apply spaceless %}
  41.         {% set sizeFallback = 100 %}
  42.         {# set largest size depending on column count of cms block #}
  43.         {% if autoColumnSizes and columns %}
  44.             {% set sizeFallback = (sizeFallback / columns)|round(0, 'ceil') %}
  45.         {% endif %}
  46.         {% set breakpoint = {
  47.             'xs': theme_config('breakpoint.xs'),
  48.             'sm': theme_config('breakpoint.sm'),
  49.             'md': theme_config('breakpoint.md'),
  50.             'lg': theme_config('breakpoint.lg'),
  51.             'xl': theme_config('breakpoint.xl')
  52.         } %}
  53.         {% if thumbnails|first.width > breakpoint|reverse|first %}
  54.             {# @deprecated tag:v6.5.0 - Variable `maxWidth` and parent condition will be removed #}
  55.             {% set maxWidth = thumbnails|first.width %}
  56.         {% endif %}
  57.         {% for key, value in breakpoint|reverse %}(min-width: {{ value }}px) {{ sizes[key] }}{% if not loop.last %}, {% endif %}{% endfor %}, {{ sizeFallback }}vw
  58.     {% endapply %}{% endset %}
  59. {% endif %}
  60. {# Is lazy loading enabled? #}
  61. {% if config('IntediaImgbolt.config.imLazyLoadingEnabled') %}
  62.    <img src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="
  63.         data-src="{{ media|sw_encode_media_url }}"
  64.        {% if media.thumbnails|length > 0 %}
  65.            data-srcset="{{ srcsetValue }}"
  66.            {% if sizes['default'] %}
  67.            data-sizes="{{ sizes['default'] }}"
  68.            {% elseif sizes|length > 0 %}
  69.            data-sizes="{{ sizesValue }}"
  70.            {% endif %}
  71.        {% endif %}
  72.        {% if attributes is not defined %}{% set attributes = {} %}{% endif %}
  73.        {% set attributes = attributes|merge({ class: attributes.class ~ ' im-lazy'}) %}
  74.        {% for key, value in attributes %}{% if value != '' %} {{ key }}="{{ value }}"{% endif %}{% endfor %}
  75.    />
  76. {% else %}
  77.    <img {% if load %}src="{{ media|sw_encode_media_url }}" {% else %}data-src="{{ media|sw_encode_media_url }}" {% endif %}
  78.        {% if media.thumbnails|length > 0 %}
  79.            {% if load %}srcset="{{ srcsetValue }}" {% else %}data-srcset="{{ srcsetValue }}" {% endif %}
  80.            {% if sizes['default'] %}
  81.            sizes="{{ sizes['default'] }}"
  82.            {% elseif sizes|length > 0 %}
  83.            sizes="{{ sizesValue }}"
  84.            {% endif %}
  85.        {% endif %}
  86.        {% for key, value in attributes %}{% if value != '' %} {{ key }}="{{ value }}"{% endif %}{% endfor %}
  87.    />
  88. {% endif %}