I have uploaded several photos to the site for a before/after slider.
Several before/after pictures should always be displayed on the page, comparable to a photo gallery.
The image name is structured according to the following scheme:
20240226_before.jpg
20240226_after.jpg
10121068977_before.jpg
10121068977_after.jpg
44011014_before.jpg
44011014_after.jpg
How do I ensure that the associated image is automatically read out based on the addition in the image name? It is very likely that 2 arrays need to be created and combined, as I did on my static page. But I have never done this with Kirby before and need your help.
I had previously used this code on my static website:
<?php
$dir = 'images/beforeafter/*';
$images = array_combine(glob($dir.'_before.*'), glob($dir.'_after.*'));
foreach ($images as $img_a => $img_b) {
echo '<div class="js-img-compare">
<div style="display: none;">
<span class="images-compare-label">Before</span>
<img src="'.$img_a.'" alt="Before">
</div>
<div>
<span class="images-compare-label">After</span>
<img src="'.$img_b.'" alt="After">
</div>
</div>';
}
?>