I’ve just been trying to implement a template function which will apply “odd” or “even” classes to alternate divs on a page. The way I’d usually do this would be to set somevar = -1, then subtract -1 from it on each loop and use the resulting -1, 0, -1, 0, -1, 0 ... state of the variable to toggle the classes:
I can’t answer your question regarding the implementation of .Scratch, but once I tried to implement the same. Your approach can be simplified by looking what the current index modulo 2 returns. If the result equals 0 it’s even, otherwise odd.
Ah. But it wouldn’t work as to toggle between two values, as per my example above. Because -1 - -1 =0 but -1 + -1 = -2
Anyway, thanks to the Linked Topic posted by @digitalcraftsman above, I managed to knock it into shape, using the code you supplied there. A bit tricky, as my actual range query was a bit more complex than I posted above. But my “if in doubt, hit it with more brackets” approach to coding did the job: