Access block indexes while using theme blocks

Previously, with section blocks, we were able to access the block index of the blocks using the for loop. Now, if we switch to using theme blocks, and render the blocks like this:
{% content_for 'blocks' %}
We can’t access the block index anymore. Is there a way to still get the indexes in Liquid while still using theme blocks?

{%- liquid
  capture children
    content_for 'blocks'
  endcapture

  for child_block in block.blocks
    assign pattern = child_block.id | split: '-' | first | append: '_index]' | prepend: '['
    assign children = children | replace: pattern, forloop.index0
  endfor
-%}

and in block add
–block-index: [{{ block.id }}_index];
or data-index: [{{ block.id }}_index];