Change sorting number of images inside a collection

,

HelloHello,

short question, because I am stuck here: is it possible to change the sorting number of site wide collected images inside a kirby collection?

I use the collection for a masonry layout

<?php

return function($site) {
    return $site
        ->index()
        ->images()
        ->filterBy('tags', 'in', collection('uniq-categories'),',')
        ->sortBy('sort', 'asc');
};

Collecting images site wide results in having the same sorting numbers in some images. But I need unique sorting numbers to jump to the right image index for a carousel.

I found a solution in my template how to do it:

<?php $counter = 0; ?>
        <?php foreach ($kirby->collection('images-tagged') as $image) : ?>
            <?php $sortNumber = $counter++; ?>

<div class="grid-item <?= Str::replace($image->tags(), ',','') ?>" data-category=" <?= Str::replace($image->tags(), ',','') ?> " id="js-project-grid" >
                    <img data-index=" <?= $sortNumber ?> "
...

But I wonder if it is not possible inside the collection somehow. I tried so many things (e.g. file→changeSort() method) but nothing worked. Or do I have to create a new array inside the collection?

Thanks in advance:)

You can use indexOf() $files->indexOf() | Kirby CMS

But using a counter is fine as well, I think.