0

I am learning interactivity API and when I tried wp-each directive, I noticed that there is no way to get the index of the array. e.g. If this is my array

$config = [
  'fruits' => [
    [
      'id'   => time() * 1000,
      'data' => [
        'apple'    => 10,
        'orange'   => 10,
        'banana'   => 10,
      ],
    ],
  ],
];

and this my HTML

render.php

  <ul data-wp-interactive="myNameSpace"
      class="gap-2 grid"
       <?php echo wp_interactivity_data_wp_context( $config ) ?>
      >
    <template data-wp-each="context.fruits"
              data-wp-key="context.item.id">
      <li class="p-2 border border-slate-100 rounded-md"
          data-wp-bind--id="context.item.id">
        <span data-wp-text="context.index"></span>
      </li>
    </template>
  </ul>

I checked the documentation and it does not include anything related to index.

1
  • What index would you need exactly? Commented 29 mins ago

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.