{% import _self as buildImage %}
{% macro setFilters(image, altText, type, originalWidth, cropping) %}
{% set imgUrl = '' %}
{% if type in ['svg', 'gif'] %}
{% set imgUrl = absolute_url(asset(image)) %}
<img class="lazy" src="{{ imgUrl }}"{% if altText %} alt="{{ altText }}"{% endif %} />
{% else %}
{% set previewSrc = croppedImgSrc(image, cropping, jml_img_large.preview) %}
{% set mobileSrc = croppedImgSrc(image, cropping, jml_img_large.mobile) %}
{% set imgSrc = croppedImgSrc(image, cropping, jml_img_large.full) %}
{#
if the container has a max-width, for example 1130px, use:
sizes="(min-width: 1130px) 1130px, 100vw"
#}
<img class="lazy" src="{{ previewSrc }}" data-srcset="{{ mobileSrc }} 480w, {{ imgSrc }} 1920w" sizes="100vw"{% if altText %} alt="{{ altText }}"{% endif %} width="{{ originalWidth }}"/>
<noscript>
<img src="{{ imgSrc }}"{% if altText %} alt="{{ altText }}"{% endif %} />
</noscript>
{% endif %}
{% endmacro %}
{% if resource.media is not empty %}
{% set image %}
{% set imageType = resource.media.originalFilename|lower|split('.')|last %}
{{ buildImage.setFilters(resource.media.url, resource.altText, imageType, resource.media.metadata.original_width) }}
{% endset %}
{% if resource.media is not empty %}
{% if app.request %}
<figure class="image-pp">
{% set imageType = resource.media.originalFilename|lower|split('.')|last %}
{% if resource.link is defined and resource.link != '' %}
<a href="{{ resource.link | replace_url }}" {% if resource.openinnewwindow %}target="_blank" rel="noopener"{% endif %}>
{{ image }}
</a>
{% else %}
{{ image }}
{% endif %}
{% if resource.caption %}
<figcaption>
<p>{{ resource.caption }}</p>
</figcaption>
{% endif %}
</figure>
{% endif %}
{% endif %}
{% endif %}