5. Refinements

The Treemenu concept is quite flexible to let you adapt it to your special needs. We will briefly discuss some refinements you might find useful:

5.1. Custom node icons

The icons used to visually describe the level and status (expanded or collapsed) of a tree node are defined in treemenu.inc:

        var $img_expand         = "blocks/treemenu/tree_expand.png";
        var $img_collapse       = "blocks/treemenu/tree_collapse.png";
        var $img_line           = "blocks/treemenu/tree_vertline.png";
        var $img_split          = "blocks/treemenu/tree_split.png";
        var $img_end            = "blocks/treemenu/tree_end.png";
        var $img_leaf           = "blocks/treemenu/tree_leaf.png";
        var $img_spc            = "blocks/treemenu/tree_space.png";

Table Table 1 shows how they look like:

Table 1. Treemenu icons

expand

Figure

collapse

Figure

vertical line

Figure

split

Figure

end

Figure

leaf

Figure

space

Figure

Of course, if you are not satisfied with the standard icons that come with the package, you may very well create your own ones. You will probably want to do so, if the theme you use has a table background for blocks other than white (the .png images that I created from the original .gif ones, do not have transparent background).

5.2. Different menus for different situations

We are now approaching the solution to our initial problem (see Section 1.3). Just because we used one Treemenu object to display only one tree does mean we are obliged to do so! We could just as well define as many input files (see Section 3.1) as categories or topics and then display the aproppriate Treemenu depending on the category or topic chosen by the user:

ob_start();
include("blocks/treemenu/treemenu.inc");
global $catid;
switch ($catid) {  (1)
  case 1:
    $tree = new TreeMenu("a", "blocks/treemenu/category1.txt"); (2)
    $tree->show();
    break;
  case 2:
    $tree = new TreeMenu("a", "blocks/treemenu/category2.txt"); (3)
    $tree->show();
    break;
  case 3:
    $tree = new TreeMenu("a", "blocks/treemenu/category3.txt"); (4)
    $tree->show();
    break;
}
$output = ob_get_contents();
ob_end_clean();
$content = $output;
(1)
The Category ID, or whatever variable whose value shall determine which Treemenu to display.
(2)
Create a new Treemenu object from the first file (which may, for example, contain only links pertaining to Category 1).
(3)
Create a new Treemenu object from the second file (which may, for example, contain only links pertaining to Category 2).
(4)
Guess what... ;-)