{% set lazyload = lazyload|default() is same as(true) ? {class: 'lazy-img', src: 'data-src', srcset: 'data-srcset', aspectRatio: true} : lazyload|default() %} {% if lazyload|default() %} {% set wrapperID = ('image-wrapper-' ~ random()) %}
{% if(lazyload.aspectRatio|default()) %}
{% endif %} {% set wrapperStyles = wrapperStyles|default([])|merge([('#' ~ wrapperID ~ ':not(.loaded){max-width:' ~ (img.width|default ? img.width ~ 'px' : 'none') ~ ';max-height:' ~ (img.height|default == 0 ? 'none' : (img.height ~ 'px')) ~ '}')]) %} {% set wrapperStyles = wrapperStyles|default([])|merge([('#' ~ wrapperID ~ ':not(.loaded) .image-aspect-ratio{padding-bottom:' ~ (img.width|default ? (img.height/img.width)*100 : 0)|number_format(2, '.') ~ '%}')]) %} {% endif %} {% if sources|default() %} {% for source in sources %} {% if lazyload|default() %} {% if source.media|default() %} {% set wrapperStyles = wrapperStyles|merge([('@media ' ~ source.media ~ '{#' ~ wrapperID ~ ':not(.loaded){max-width:'~ (source.width == 0 ? 'none' : (source.width ~ 'px')) ~';max-height:' ~ (source.height == 0 ? 'none' : (source.height ~ 'px')) ~ '}}')]) %} {% set wrapperStyles = wrapperStyles|merge([('@media ' ~ source.media ~ '{#' ~ wrapperID ~ ':not(.loaded) .image-aspect-ratio{padding-bottom:' ~ (source.width == 0 ? 0 : (source.height/source.width)*100)|number_format(2, '.') ~ '%}}')]) %} {% endif %} {% else %} {% endif %} {% endfor %} {% endif %} {% if lazyload|default() %} {{ alt|raw }} {% else %} {{ alt|raw }} {% endif %} {% if sources %} {% endif %} {% if lazyload|default() %} {% apply spaceless %} {% endapply %} {% if(lazyload.aspectRatio|default()) %}
{% endif %}
{% endif %} {% if sources|default() or img.src != img.srcset %} {% endif %}