Articles » Administrator » Mastering the Menu #1
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 #1

This article is the first in a series of articles that will give help you become a master of using the printMenu() method available in the Fundanemt parser.

Some time ago the method used when inserting a menu on a Fundanemt powered website were rewritten and renamed from printClientMenu to printMenu. The new menu method includes many features, most of which have not been documented until now. We - the Fundanemt team - have discovered that most users requesting new features or asking how a certain layout idea can be implemented are already possible with the current implementation of the menu. The users just did not know, and this is what this article series is here for - to help you realize your ideas.

An empty arrMS parameter

By sending no parameters at all or by sending an empty string as the first parameter to the printMenu method, it will default to a standard list-based menu with CSS classes on both the list-items and the links for each menu item.

<?php
    $parser
->printMenu();
    
$parser->printMenu("", .., ..);
?>

Menu Item Keywords

When styling a menu item, the printMenu method allow you to specify what and where different information about the menu item should be written in the output HTML. The details are available in the form of keywords, which are replaced with the actual information when the printMenu method processes the menu item templates and fill in data from the menu.

  • CLASS: CSS class name of the menu item type, e.g. OOO_l1 (<menu-type>_l<menu-item-level>)
  • COUNT: Index of the page in the current menu level.
  • PAGEID: The ID of the page associated with the menu item.
  • URL: Url of the menu item based on the current url type.
  • TITLE: Title of the page.

Menu Item Types

At first the different menu item types can be a bit confusing. I will try to describe the different types here. The menu item type key consists of three characters, which each indicate a property of the menu item.

I = true
O = false

  1. Page is currently viewed
  2. Page has a sub menu
  3. Sub menu is currently shown


The menu item types described below are specified as keys in the style array (arrMS) sent to the printMenu method.

  • IOO: Page is active, but does not have a sub menu.
  • III: Page has a sub menu and is currently active, and thus the sub menu is also displayed.
  • OIO: Page is not active and has a sub menu, which is not shown.
  • OOO: Page is not active and it does not have a sub menu.
  • OII: A menu item in the sub menu of this page is viewed.


Besides the menu item types described above, it is possible to define styles that are used when a sub-menu with the current level is being processed and when it is done being processed. Can be used to list by placing <ul> and </ul> around sub menus.

  • BEGIN
  • END

Crafting a arrMS Menu Template

The arrMS consists of styles for each menu item type on each menu level that you wish to have displayed. If a menu item type is left out, it will not be included in the menu output, and if a menu level is left out, no menu items from that menu will be printed. The last option can be used only display level one menu items in a top-menu - more on this later.

Level 0 is used as a fall back level, so if a menu item can not be matched against a menu level or menu item type, the printMenu method will look for a style in this level.

Below we declare two menu style arrays - one for the top menu (only level one menu items) and one for the side menu, which includes the rest of the levels. The sideMenu variable declare that no top level menu items should be included and the rest should be printed using the specified style.

<?php
    $topMenu 
= array(
        
=> array(
            
'IOO'   => '<a href="URL" class="active">TITLE</a>'."\n",
            
'III'   => '<a href="URL" class="active">TITLE</a>'."\n",
            
'OIO'   => '<a href="URL">TITLE</a>'."\n",
            
'OOO'   => '<a href="URL">TITLE</a>'."\n",
            
'OII'   => '<a href="URL" class="subactive">TITLE</a>'."\n"
        
)
    );

    
$sideMenu = array(
        
=> array(),
        
=> array(
            
'IOO'   => '<li><a href="URL" class="active">TITLE</a></li>'."\n",
            
'III'   => '<li><a href="URL" class="active">TITLE</a></li>'."\n",
            
'OIO'   => '<li><a href="URL">TITLE</a></li>'."\n",
            
'OOO'   => '<li><a href="URL">TITLE</a></li>'."\n",
            
'OII'   => '<li><a href="URL" class="subactive">TITLE</a>'."\n",
            
'BEGIN' => '<ul>',
            
'END'   => '</ul>'
        
),
    );
?>

We then create a simple Fundanemt template, that call the printMenu method twice. Once for the top menu, and once for the side menu. This way you can split up your menu into separate menus.

<html>
  <head>...</head>
  <body>
    <div id="topmenu">
      <?php $parser->printMenu($topMenu); ?>
    </div>

    <div id="main">
      <div id="sidemenu">
        <?php $parser->printMenu($sideMenu); ?>
      </div>
      <div id="content">
        <?php $parser->printSiteContent(); ?>
      </div>
    </div>
  </body>
</html>

Summary

This article has shown how the arrMS parameter can be used to split the menu into several menus, the different keywords and menu item types.

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.