Tree-construction methods

Actually, you have three different methods to build the tree:

By hand

This is the 'hard' way, like the example above. You have to set each node by hand.

Importing XML

You can import a formatted XML file into the tree structure. It supports string of XML_Tree object :)

XML Format

<treemenu>
  <node text="First node" icon="folder.gif" expandedIcon="folder-expanded.gif" />
  <node text="Second node" icon="folder.gif" expandedIcon="folder-expanded.gif">
    <node text="Sub node" icon="folder.gif" expandedIcon="folder-expanded.gif" />
  </node>
  <node text="Third node" icon="folder.gif" expandedIcon="folder-expanded.gif">
</treemenu>

Example with a string (not tested)

<?php
require_once 'HTML/TreeMenu.php';

// Load the XML file
$xml file_get_contents('tree.xml');

$menu = new HTML_TreeMenu();
$menu->createFromXML($xml);

// Chose a generator. You can generate DHTML or a Listbox
//$tree = new HTML_TreeMenu_Listbox($menu);
$tree = new HTML_TreeMenu_DHTML($menu);

echo 
$tree->toHTML();

?>
Simple example (Previous) Pager (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.