Slideshow with numbers

Hi Kirby-Forum!

I have a custom js image slider that should echo the number of all slides as well as the number of the current slide (e.g. “Image 4 of 15”). I usually do this with JS, but as PHP-beginner who recently found out about the ->count() option I wanted to ask you if there is a way with PHP to show the number of the current item within this foreach loop?

(The images are sorted in a structure field)

Thanks in advance

You can use indexOf() to get the number of the current item in the collection (if you use toStructure() to convert your structure field into a collection, doesn’t work with yaml(), since that returns an array)

https://getkirby.com/docs/toolkit/api/collection/index-of

1 Like

Sry, just saw I never thanked you for your help. Tried it, worked – but as JS fan went for JS in the end :wink:

1 Like