Documentation

Init

bool
CMenu::Init(
 string InitDir
 bool MenuExt = false,
 string template = false,
 onlyCurrentDir=false
)

The method initializes the CMenu class object (fills it with menu items). Returns true if the site directory contains the .menu type.menu.phpmenu file (the search is performed up the directory hierarchy starting from the folder dir). Otherwise, it returns false. Non-static method.

Parameters

ParameterDescription Available from version
InitDir The folder from which the search for file .menu type.menu.php is performed (file with menu items and parameters).
MenuExt If true, If true the file .menu type.menu.php will be included in addition to .menu type.menu_ext.php. to create the menu array. These files allow to handle the menu array$aMenuLinks as desired, по (for example: add menu items from information blocks).
Optional parameter. By default value is false.
template Template used to display menu.
Optional parameter. By default value is false false, which means first searching for the template in the file /bitrix/templates/current site template ID/menu type.menu_template.php, If the template cannot be found, the file /bitrix/templates/.default/menu type.menu_template.php will be searched. The following preset variables are available in the template:
  • $arMENU - copy of menu array;
  • $arMENU_LINK - link to the current menu array;
  • $TEXT - text of the current menu item;
  • $LINK - link on the current menu item;
  • $SELECTED - whether the menu item is currently selected;
  • $PERMISSION - access permission for the page specified in the $LINK field. Following values are possible:
    • D - access denied;
    • R - read access (view the file contents);
    • U - workflow (edit file in the workflow mode);
    • W - write (direct modification is allowed);
    • X - full access (both direct file modification and editing the access permission are allowed).
  • $ADDITIONAL_LINKS - additional links for menu highlighting;
  • $ITEM_TYPE - "D" - stands for directory (if $LINK ends with "/"), otherwise "P" (page);
  • $ITEM_INDEX - menu item ordinal;
  • $PARAMS - parameters of menu items.
The menu template needs to have the following variables initialized:
  • $sMenuProlog - the HTML code to add before menu items;
  • $sMenuEpilog - the HTML code to add after menu items;
  • $sMenuBody - the HTML code describing a menu item;
  • $sMenu - the HTML code describing the whole menu (only for GetMenuHtmlEx method).
$onlyCurrentDir If true - file menu search is disabled in Parent catalogues.

See Also

Examples of use

<?
$lm = new CMenu("left");
$lm->Init($APPLICATION->GetCurDir(), true);
$lm->template = "/bitrix/templates/demo/left.menu_template.php";
echo $lm->GetMenuHtml();
?>


© «Bitrix24», 2001-2024