Hi,
I’m develloping a website to learn kirby.
I’d like to give my image a specific id using their position in the grid from my panel.
For exemple, if my image is the third in the panel, it will have “3” as an ID.
Actually i’m using $image->hash() in order to give a unique id to each image, but it’s not as clean as I expected…
Am I missing something?
If all images have a sorting number (i.e. you manually sort them in the Panel), you can get the sorting number with $image->sort().
Alternatively, you can print the index of the file in the collection inside the loop, example:
<?php
$images = page->images()->sortBy('sort');
foreach ($images as $image) {
echo $images->indexOf($image) + 1; // + 1 because the index starts at zero.
}