Here\'s my php script:
Store the depth in a variable and check if the variable has been increased or decreased each loop?
If the depth has been increased, you add another tag and if it has been decreased you add a closing tag.
Each loop would always output the tags to wrap the filename.
e.g.
$depth = 0;
foreach ($objects as $name => $object) {
$depth2 = $objects->getDepth();
if($depth2 > $depth) { echo ''; }
echo "- " . $object->getFilename() . "
";
if($depth2 < $depth) { echo '
'; }
$depth = $depth2;
}
That would need some additional testing and modification to suit your existing code, but hopefully it gives you some ideas.