Structure row index numbering

I’m not sure if this is possible in Kirby.

I have a structure type field in my projects panel. (Refer to the screenshot below)
I was wondering if its possible to auto-number the rows ascendingly each time i add / remove / re-order them.

Currently i’m numbering them manually, so that means each time i remove or reorder a row, i have to change the index number manually.

Is it possible to write something in the .yml file to see which index the row is and automatically fill the index field with it?

P.S : I’m not accessing this field on the client side, just wanted to have a neat row numbering on the panel side.

Why do you need the index at all if it is supposed to change?

Edit: Maybe you could use the snippet field instead of the structure field, then make the index a readonly field that only displays a number via a snippet without actually storing anything (just an idea, haven’t tested this).

thanks for the reply. im currently trying out the snippet field plugin.

I’ve managed to link a custom snippet to the index field and display the same thing.
but i have no idea what i should do to incrementally increase the value in the snippet. hmm

ive tried something like this in the snippet:

 <?php $i = 0;  foreach($page->grid()->toStructure() as $gridder): ?>  
  <?= $i++ ?>
 <?php endforeach ?>

but im getting the increment ofr index field within each row instead:

I thought it would be possible to get the index of the item in the structure field, but for this to work, there would have to be some unique value to find the correct item within the structure.

And it seems the snippet is only shown if the field contains a value, not if it is empty. Another downside is that the value is only displayed after saving…

You can always use a hook that renumbers your index when a page is saved, but that then only happens on save as well.

I knew I’d seen this problem before so I searched again and found this solution: Panel - Display the current position on structure entry (+ kirby-snippetfield)

No hooks, no fiddling…

1 Like

Yess changing the contents of the table via css did it! Thanks @texnixe ! Have a good day!