44 lines
2.3 KiB
Twig
44 lines
2.3 KiB
Twig
{# html #}
|
|
<p id="{{ id }}">
|
|
{%~ for image in images %}
|
|
<a href="{{ image["src"] }}" class="glightbox-{{ id }}"
|
|
{#- add description, if enabled #}
|
|
{%- if descEnabled == "true" %}
|
|
{{- "" }} data-description="{{ image["desc"]|raw }}"
|
|
{%- endif %}
|
|
>
|
|
{#~ try to generate a thumbnail image #}
|
|
{#- get the full image url https://mywebsite.com/user/pages/02.gallery/01.landscapes/image01.jpg #}
|
|
{%- set original_image = image["src"] %}
|
|
{#- remove the sites url /user/pages/02.gallery/01.landscapes/image01.jpg #}
|
|
{%- if base_url %}
|
|
{%- set original_image = original_image|replace({(base_url): ""}) %}
|
|
{%- endif %}
|
|
{#- remove "/user/" pages/02.gallery/01.landscapes/image01.jpg #}
|
|
{#- be careful, a page can be named "user", only replace the first occurence #}
|
|
{%- set original_image = original_image|split("/user/", 2) %}
|
|
{#- add "user://" user://pages/02.gallery/01.landscapes/image01.jpg #}
|
|
{%- set original_image = "user://" ~ original_image[1] %}
|
|
{#- use the generated url to get the image via grav (can load any image in the /user directory) #}
|
|
{%- set original_image = page.media[original_image] %}
|
|
{#- success: can now generate a smaller thumbnail image #}
|
|
{%- if original_image %}
|
|
{%- set estimated_thumb_width = ( original_image.width * rowHeight / original_image.height ) | round %}
|
|
{#- force the use of the first image in srcset (thumbnail) with sizes="1px" #}
|
|
{#- RSS readers shouldn't use srcset images, otherwise they will display something similar to JG, but not justified #}
|
|
{#- width and height to avoid Justified Gallery loading the image from "src" attribute #}
|
|
{{ original_image
|
|
.derivatives( [ ( estimated_thumb_width * resizeFactor ) | round ] )
|
|
.sizes( "1px" )
|
|
.width( estimated_thumb_width )
|
|
.height( rowHeight )
|
|
.loading.html(image.title, image.alt)|raw }}
|
|
{#~ couldn't find the image inside grav, so just use the original url #}
|
|
{%- else %}
|
|
{{ image["image"]|raw }}
|
|
{{- "\n" }}
|
|
{%- endif %}
|
|
</a>
|
|
{%~ endfor %}
|
|
</p>
|