<?php foreach ($records as $record): ?>

    <li data-record-id="<?= $record->id ?>">
        <div class="record">
            <a href="javascript:;" class="move"></a>
            <span><?= $record->name ?></span>
        </div>

        <ol data-parent-id="<?= $record->id ?>">
            <?php if ($record->getChildren()): ?>
                <?php
                $children = $record->getChildren();
                if ($this->index) {
                    $children->sortBy($this->index);
                }
                ?>
                <?= $this->makePartial('tree_records', ['records' => $children]) ?>
            <?php endif ?>
        </ol>

    </li>

<?php endforeach ?>
