tree(), li_tree() html()

An editable tree (drag and drop, expand / collapse) from a flat id => item list with parent_id; li_tree() is the nested <ul> without the editor.

html()->tree($data = [], $extra = [])
html()->li_tree($data = [], $extra = [])

Options

OptionMeaning
$dataId => ['name', 'link', 'parent_id'] (also icon_class, badge, class_badge, and active: a falsy value dims the row and says so in words). name is HTML and is output as it is: pass stored text through _prepare_html(); the other values are escaped.
form_action, form_class, draggableWhere the drag form posts the new order; its class; drag and drop on or off.
show_controls, add_link, edit_link, delete_link, clone_link, back_link, add_no_ajaxRow buttons and the links they open.
opened_levels, no_expand, class_add, idLevels open on load; no expand buttons; classes (no_hide_controls: row buttons always shown); id.
linesA rule under every row across the tree, as before 2026-11-16 (rows are otherwise as wide as their content).

Example

li_tree()

  • Root
    • Child
  • Code

    $items = [
        11 => ['name' => 'Tools'],
        22 => ['link' => '#blocks', 'name' => 'Blocks editor', 'parent_id' => 11],
        33 => ['link' => '#file_manager', 'name' => 'File manager', 'parent_id' => 11],
        44 => ['name' => 'Administration'],
        55 => ['link' => '#admin', 'name' => 'Admin accounts', 'parent_id' => 44],
        66 => ['link' => '#admin_groups', 'name' => 'Admin groups', 'parent_id' => 44],
        77 => ['link' => '#admin_modules', 'name' => 'Admin modules', 'parent_id' => 44],
        88 => ['name' => 'Users', 'parent_id' => 44],
        99 => ['link' => '#manage_users', 'name' => 'User accounts', 'parent_id' => 88],
        101 => ['link' => '#user_groups', 'name' => 'User groups', 'parent_id' => 88],
        102 => ['link' => '#user_modules', 'name' => 'User modules', 'parent_id' => 88],
        103 => ['name' => 'Content'],
        104 => ['link' => '#static_pages', 'name' => 'Static pages', 'parent_id' => 103],
        105 => ['link' => '#manage_news', 'name' => 'News', 'parent_id' => 103],
        106 => ['link' => '#manage_comments', 'name' => 'Comments', 'parent_id' => 103, 'active' => 0],
    ];
    return html()->tree($items) . '<h4>li_tree()</h4>' . html()->li_tree([1 => ['name' => 'Root'], 2 => ['name' => 'Child', 'parent_id' => 1]]);

    Notes

    • The editor (yf_draggable_tree, jQuery UI draggable) posts the rows that moved as JSON in items ({index: {item_id, parent_id}}) to the form action, with the session token when the admin CSRF guard is on; the menu and category editors of the admin use it.
    • Row buttons (show_controls) are icon-only admin UI kit buttons right after the label, inside the row: shown on hover (and a moment after the pointer leaves the row) and on keyboard focus, always on touch screens. An Active button of the row (change_active) updates the dimmed look at once.
    • Keyboard: the tree is a WAI-ARIA tree with one tab stop. Up / Down walk the rows, Right / Left open or close a branch and go to its first child or its parent, Home / End, a letter jumps to the next row starting with it, Enter follows the row's link, Tab reaches the row's buttons. Space picks a row up; Up / Down then move it among its siblings, Left out of its parent, Right into the row above; Space or Enter drops it, Escape puts it back, each step read out by screen readers. The ? button by Save lists the keys. A keyboard move saves exactly like a mouse drop, and Ctrl+Z undoes it.

    See also: html/menu, form/tbl_link