How to loop through a nested structure?

Since agendas is also a structure field, you have to call toStructure() on it as well, whereas your first toStructure() call is not correct:

$checkboxes = $page->checkboxes()->toStructure();
foreach ( $checkboxes as $checkbox ) {
  $agendas = $checkbox->agendas()->toStructure();
  foreach ( $agendas as $agenda ) {
    echo $agenda->title();
    echo $agenda->tag();
  }
}
2 Likes