DHTML Menu Studio FAQ

Question ID:
Q3049
Question:
How can I dynamically create the menu structure using a server-side scripting language?
 
With the professional edition of DHTML Menu Studio you can insert items into the menu dynamically, from a server-side script such as PHP, ASP, ASP.NET or ColdFusion. This is very useful if you want to reflect a structure stored in a database or enable/disable items based on user's permissions. You can enable dynamic generation in options / output / dynamic creation of menu structure. NOTE: If using a bitmap scheme (and the top-level menu generation method is not set to HTML code) you will only be able to dynamically create popups. You will not be able to modify top-level menu items. The reason for this is that in such case, the program creates the top-level menu in form of image files containing fixed texts chosen at the design time.
Adding items to menu
When dynamic creation is enabled, in the ouput page created by DHTML Menu Studio you will notice JavaScript / PHP / ASP / ASP.NET / ColdFusion functions which should be called to dynamically add items to the menu. Please note that when creating the menus, you don't specify the position of items -- all items are always inserted at the end of a given menu (top-level menu bar or popup). The code for dynamic menu creation should be inserted just after the Add items to the menu here comment (the program will also create default code at this location -- this code will create a menu designed inside the program's UI). Below is the description of the functions you'll need to use:
function SSAddTopLevelMenu -- call this function to add a popup menu to the top-level menu bar (use SSAddMenuItem to add items which do not expand into a popup, instead). The function returns the id of the created menu (this id can be used as the parentMenu parameter when adding child items to the menu). This function accepts the following parameters:
  • itemText -- text of the item (can be HTML code).
  • itemUrl -- URL the item links to (can be empty). This can also be a JavaScript function call (in such case use the javascript: prefix).
  • targetFrame -- target frame for the specified URL (can be empty). To open item in a new window, enter _blank.
  • itemIcon -- url of the icon to be displayed next to the item (can be empty)
  • nMenu -- identifies the menu bar being created. If creating a single menu bar, enter m1. For the second menu, enter m2 etc. If using PHP, you can leave this parameter empty, when creating a single menu.
function SSAddSubMenu -- call this function to add a popup menu as a child of another popup menu (to add popup menus to the top-level menu bar, use SSAddTopLevelMenu). The function returns the id of the created menu (this id can be used as the parentMenu parameter when adding child items to the menu). This function accepts the following parameters:
  • itemText -- text of the item (can be HTML code).
  • itemUrl -- URL the item links to (can be empty). This can also be a JavaScript function call (in such case use the javascript: prefix).
  • targetFrame -- target frame for the specified URL (can be empty). To open item in a new window, enter _blank.
  • parentMenu -- identifier of the parent menu into which the popup will be inserted. This is the identifier being returned by the SSAddTopLevelMenu, SSAddSubMenu, or SSGetTopLevelMenu functions.
  • itemIcon -- url of the icon to be displayed next to the item (can be empty)
  • nMenu -- identifies the menu bar being created. If creating a single menu bar, enter m1. For the second menu, enter m2 etc. If using PHP, you can leave this parameter empty, when creating a single menu.
function SSAddMenuItem -- call this function to add a menu item which does not expand a popup (if you want to create an item which expands into a popup, use SSAddTopLevelMenu or SSAddSubMenu). This function accepts the following parameters:
  • itemText -- text of the item (can be HTML code).
  • itemUrl -- URL the item links to (can be empty). This can also be a JavaScript function call (in such case use the javascript: prefix).
  • targetFrame -- target frame for the specified URL (can be empty). To open item in a new window, enter _blank.
  • parentMenu -- identifier of the parent menu into which the item will be inserted. When inserting into the top-level menu bar, enter null. When inserting into a popup, this is the identifier being returned by the SSAddTopLevelMenu or SSAddSubMenu functions.
  • itemIcon -- url of the icon to be displayed next to the item (can be empty)
  • nMenu -- identifies the menu bar being created. If creating a single menu bar, enter m1. For the second menu, enter m2 etc. If using PHP, you can leave this parameter empty, when creating a single menu.
function SSGetTopLevelMenu -- this function returns the id of a top-level menu created statically by DHTML Menu Studio at design time (the top-level menu bar is created statically when top-level items are created as images). You can use the id returned by this function in subsequent calls to SSAddSubMenu.
  • nSubMenu -- index of the top-level menu item being returned. For the first pop-up menu, enter 1, for the second enter 2 etc.
  • nMenu -- identifies the menu bar being created. If creating a single menu bar, enter m1. For the second menu, enter m2 etc. If using PHP, you can leave this parameter empty, when creating a single menu.
Here's a sample code (PHP version) which creates the whole menu (top-level bar and popups):
...

// --------------------------
// Add items to the menu here
// --------------------------

// adding top-level items
$e_1=SSAddTopLevelMenu("Sample folder 1","", "");
$e_2=SSAddTopLevelMenu("Sample folder 2","http://www.xtreeme.com/", "");

// adding first popup items (and a sub-popup)
SSAddMenuItem ("Item","http://www.google.com/", "",$e_1);
$e_1_1=SSAddSubMenu("Subfolder","http://www.yahoo.com/", "",$e_1);
SSAddMenuItem ("Item opened in a new window","http://www.msn.com/", "_blank",$e_1_1);

// adding item to second popup
SSAddMenuItem ("Item","http://www.pixel-peeper.com/", "",$e_2);

...

Here's a sample code (PHP version) which creates popups only (top-level menu created at images):
...

// --------------------------
// Add items to the menu here
// --------------------------

// getting IDs of top-level items
$e_1=SSGetTopLevelMenu(1);
$e_2=SSGetTopLevelMenu(2);

// adding first popup items (and a sub-popup)
SSAddMenuItem ("Item","http://www.google.com/", "",$e_1);
$e_1_1=SSAddSubMenu("Subfolder","http://www.yahoo.com/", "",$e_1);
SSAddMenuItem ("Item opened in a new window","http://www.msn.com/", "_blank",$e_1_1);

// adding item to second popup
SSAddMenuItem ("Item","http://www.pixel-peeper.com/", "",$e_2);

...
The above samples will result in the following structure being created:
Sample folder 1
	Item
	Subfolder
		Item opened in a new window
Sample folder 2
	Item
Click here for a reusable (typical-use) sample in PHP+MySQL, ASP+ODBC, ASP.NET and ColdFusion