Structured content with unknown number of "fields"

I’m working on ways to build out tabular data without having to build tables, and structured content with the toStructure() function has been a lifesaver. However, I’ve run into a snag: The new rows of data don’t line up in a completely tabular fashion. For example, the data might look something like this (this being a sample field from a kirby content page):

training:

-
title: Item 1
detail1: Details about Item 1
detail2: Details about item 1
-
title: Item 2
detail1: Details about item 2
detail2: Details about item 2
detail3: Details about item 2

So what I want to be able to do is call all the detail fields from each structured item, without having to know in advance how many detail items there are for each. What I’ve done previously is called each sub-field, which is all I’ve found instructions for, but somehow I’d like to loop through all the sub-fields for an item (maybe by name, like all that start with detail), and display them, because they won’t all have the same number.

Worst case, I guess, is I can create code to call up to like 5 detail fields, and then only display if they’re not empty. But I’d also like to count them to use that number elsewhere, so that gets more complicated.

Does anybody understand what I’m saying, and can anyone help me with this? Or recommend some method other than structured content for this?

Don’t know if I get you right, but how about a nested foreach loop, something like this:

<table>
  <?php foreach($page->training()->toStructure() as $item): ?>
  <?php $count = count($item) ?>
    <tr>
      <?php foreach($item as $key => $detail): ?>
        <td><?= $detail ?></td>
      <?php endforeach ?>
    </tr>
  <?php endforeach ?>
 </table>

OK, yes, this basically works. Because I want to handle the title field separately, and this includes all of them, I can just either drop the first one in the loop, or check the title value against the detail value and leave it off if it matches, since the title may not necessarily be the first field as it should be.

I was thinking, though: YAML supports nested lists, correct? Is there a way to use nested YAML lists in Kirby? I’m not really finding anything about that, or what the syntax would be.

If you don’t use the Panel, you could do it like this:

Training:

- title: Some title
    - details:
        - detail1: An important detail
        - detail2: A less important detail
- title: Some other title
    - details:
        - detai1l: A little detail

In your template:

<?php
$training = $page->training()->yaml();
var_dump($training);
?>