Articles » Administrator » Mastering the Menu #3
Author

Brian Jørgensen is a 9th semester, Software Engineering student at Aalborg University. He works as a freelance developer and on Fundanemt.

Website
E-mail

Mastering the Menu - Article #3

This is the third article in a series of articles on the printMenu() method.

This article will describe how you can specify general settings for the menu using different values for the style parameter. The style parameter is specified as an associative array with options as keys and associated values. If the parameter value is a string instead of an array, it is interpreted as a value for the style option.

printMenu("", false, "normal")
is thus equvivalent
array("style" => "normal")

"style" Option

The style option is used to define how the printMenu() method should handle sub-menus. The menu can either be a standard menu or it can be a list (using UL and LI tags). If the option is set to "list", LI tags will be opened and closed correctly for sub-menus.

<?php
    
// Default value
    
$parser->printMenu(""false);

    
// Specifying using a string
    
$parser->printMenu(""false"normal");

    
// Get a normal menu behavior with no extra handling
    
$parser->printMenu(""false, array("style" => "normal"));

    
// Get a menu with list behavior
    
$parser->printMenu(""false, array("style" => "list"));
?>

"max_level" Option

The "max_level" option is used to easily limit the depth of the menu.

<?php
    $parser
->printMenu(""false, array("max_level" => 1);
?>

Limiting the menu tree to a depth of 1 is equvivalent to only having an entry for depth 1 in the array menu style (arrMS) as described in the first article.

<?php
    $arrMS 
= array();
    
$arrMS[1]["IOO"] = "<li class=\"li_CLASS\"><a href=\"URL\" class=\"CLASS\"$target>TITLE</a></li>\n";
    
$arrMS[1]["III"] = "<li class=\"li_CLASS\"><a href=\"URL\" class=\"CLASS\"$target>TITLE</a></li>\n";
    
$arrMS[1]["OIO"] = "<li class=\"li_CLASS\"><a href=\"URL\" class=\"CLASS\"$target>TITLE</a></li>\n";
    
$arrMS[1]["OOO"] = "<li class=\"li_CLASS\"><a href=\"URL\" class=\"CLASS\"$target>TITLE</a></li>\n";
    
$arrMS[1]["OII"] = "<li class=\"li_CLASS\"><a href=\"URL\" class=\"CLASS\"$target>TITLE</a></li>\n";
    
$arrMS[1]["BEGIN"] = "<ul class=\"ul_CLASS\">\n";
    
$arrMS[1]["END"] = "</ul>\n";

    
$parser->printMenu($arrMSfalse"list");
?>

"breaks" Option

By default page titles are printed with non-brekable spaces in menu items. This can cause some unwanted problems in some layout situations, and it is thus made possible to turn of this behavior. If the "breaks" option is specified in the style parameter array, &nbsp; (non-brekable spaces) will be converted to normal spaes.

<?php
    $parser
->printMenu(""false, array("breaks" => true);
?>

Summary

In this article we have seen a quick introduction of the different options for the +bstyle- parameter of the printMenu method. It can be used to easily customize the behavior of the printMenu method.

Article Series

#1 Introduction to printMenu - arrMS parameter
This article gives an introduction to the printMenu method and describe the different menu item templates and how they can be styled.

#2 Show parameter
This article gives examples on how the show parameter can be used to expand sub-menus.

#3 Style parameter
This article describe how the style parameter can be used to control how the printMenu method acts, e.g. if it should use non-breaking spaces and maximum number of menu item levels to print.

#4 Mode parameter
This article explain how to use the mode parameter to control if the printMenu method should include hidden pages.