Documentation

GetMenuHtmlEx

string
CMain::GetMenuHtmlEx(
 string type = "left",
 bool MenuExt = false,
 mixed template = false,
 mixed InitDir = false
)

The method returns the HTML code that can be used to display menu. Unlike the CMain::GetMenuHtml method the menu template will be included only once. Non-static method.

Note. The menu template used by this function must explicitly initialize the variable $sMenu, with the HTML code describing the whole menu.

Parameters

ParameterDescription Available from version
type Menu type.
Optional parameter. By default, the value is left.
MenuExt If true, to create the menu array, that will include in addition to the files .menu type.menu.php also files with such names as .menu type.menu_ext.php. You can configure the $aMenuLinks menu array arbitrarily at your discretion. (for example, by adding menu items with values sourced from information blocks).
Optional parameters. The default value is false.
template Pathrelative to the root for the menu template.
Optional. By default value is false, which means to search as per the algorithm, specified at the означает ''Create and display menu'' page и показ меню.
InitDir Directory for which the menu will be created.
Optional parameter. False, be default, which means the current directory.

See Also

Examples of dropdown top menu

Print menu in the file /bitrix/templates/demo/header.php:

<script language="JavaScript1.2" src="/bitrix/templates/demo/js/ddnmenu.js"></script>
<?echo $APPLICATION->GetMenuHtmlEx("top");?>

File /.top.menu.php:

<?
// main menu file 
// this file can be edited in the menu editor
$aMenuLinks = Array(
    Array(
        "Main", 
        "/index.php", 
        Array(), 
        Array(), 
        "" 
    ),
    Array(
        "Directory", 
        "/catalog/", 
        Array(), 
        Array(), 
        "" 
    ),
    Array(
        "Support", 
        "/support/", 
        Array(), 
        Array(), 
        "" 
    ),
    Array(
        "Partners", 
        "/partners/", 
        Array(), 
        Array(), 
        "" 
    ),
    Array(
        "Company", 
        "/about/", 
        Array(), 
        Array(), 
        "" 
    )
);
?>

File /bitrix/templates/demo/top.menu_template.php:

<?
// menu template
$sMenu = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="0%"><img src="/bitrix/templates/demo/images/top_menu_corner.gif" alt="" width="15" height="19"></td>';

for($i=0; $i<count($arMENU); $i++)
{
    $MENU_ITEM = $arMENU[$i];
    extract($MENU_ITEM);

    if($SELECTED)
        $clrtext = 'topmenuact';
    else
        $clrtext = 'topmenu';

    $sMenu .= '<td>';
    $sMenu .= '<table border="0" cellspacing="0" cellpadding="0"><tr>';
    $sMenu .= '<td bgcolor="#7B9DBB" onmouseo ver="show('.$i.')" onmouse out="hidden('.$i.')"><a href="'.$LINK.'" class="'.$clrtext.'"><nobr> '.$TEXT.' </nobr></a></td>';
    $sMenu .= '<td width="0%" bgcolor="#7B9DBB">';

    if($i<count($arMENU)-1) //add vertical divider after all items but not after the last one
        $sMenu .= '<img src="/bitrix/templates/demo/images/top_menu_divider.gif" width="15" height="19" alt="">';
    else
        $sMenu .= '<img src="/bitrix/templates/demo/images/1.gif" width="1" height="19" alt="">';

    $sMenu .= '</td></tr></table>';

    //check if menu of left type exists in the folder that the menu item points to
    $popup_menu = new CMenu("left");
    $popup_menu->Init($LINK);
    if(count($popup_menu->arMenu) > 0)
    {
        //if left menu exists then we display it in the hidden layer
        $popup_menu->template = "/bitrix/templates/demo/popup.menu_template.php";
        $sMenu .= '<div style="position:relative; width: 100%;">';
        $sMenu .= '<div onMouseO ver="show('.$i.')" onMouse Out="hidden('.$i.')" id="menu'.$i.'" st yle="visibility: hidden; position: absolute; z-index: +1; top: 0px;" >';
        $sMenu .= $popup_menu->GetMenuHtmlEx();
        $sMenu .= '</div></div>';
    }
    $sMenu .= '</td>';
}
$sMenu .= '<td width="100%" bgcolor="#7B9DBB"><img src="/bitrix/templates/demo/images/1.gif" width="50" height="1" alt=""></td></tr></table>';
?>

Файл /bitrix/templates/demo/popup.menu_template.php:

<?
$sMenu =
    '<table border="0" cellspacing="0" cellpadding="0" width="110">'.
    '<tr><td bgcolor="#E6EFF7" valign="top"><table border="0" cellspacing="0" cellpadding="0" width="100%">';

for($i=0; $i<count($arMENU); $i++)
{
    $MENU_ITEM = $arMENU[$i];
    extract($MENU_ITEM);

    if ($PERMISSION > "D")
    {
        $sMenu .=
        '<tr valign="top"><td nowrap onmouseo ver="this.className=\'popupmenuact\'" onmouse out="this.className=\'popupmenu\'" oncl ick="window.location=\''.$LINK.'\'"  class="popupmenu" style="cursor: hand">'.
        '<nobr><a href="'.$LINK.'" style="text-decoration: none;"><font class="popupmenutext">'.$TEXT.'</font></a>'.
        '</nobr></td></tr>';
    }
    else
    {
        $sMenu .=
        '<tr valign="top"><td nowrap onmouseo ver="this.className=\'popupmenuact\'" onmouse out="this.className=\'popupmenu\'" oncl ick="window.location=\''.$LINK.'\'"  class="popupmenu" style="cursor: hand">'.
        '<nobr><font class="popupmenuclosed">'.$TEXT.'</font>'.
        '</nobr></td></tr>';
    }
}
$sMenu .= '</table></td></tr></table>';
?>

File /bitrix/templates/demo/js/ddnmenu.js:

var brname=navigator.appName, BrVer='';
if(brname.substring(0,2)=="Mi")
    BrVer='E';
var timer = 0;
lastid = -1;

function show(id)
{
    if(!((document.all)?document.all['menu'+id]:document.getElementById('menu'+id)))
        return;
    clearTimeout(timer);
    if((id != lastid) && (lastid!=-1))
        ((document.all)?document.all['menu'+lastid]:document.getElementById('menu'+lastid)).style.visibility = 'hidden';
    hideElement("SELECT", document.getElementById('menu'+lastid));
    lastid = id;
    ((document.all)?document.all['menu'+lastid]:document.getElementById('menu'+lastid)).style.visibility = 'visible';
}

function hidden(id)
{
    if(!((document.all)?document.all['menu'+id]:document.getElementById('menu'+id)))
        return;
    showElement("SELECT");
    timer = setTimeout("if('"+id+"' == '"+lastid+"'){((document.all)?document.all['menu"+lastid+"']:document.getElementById('menu"+lastid+"')).style.visibility = 'hidden';}", 500)
}


function GetPos(el)
{
    if (!el || !el.offsetParent)return false;
    var res=Array()
    res["left"] = el.offsetLeft;
    res["top"] = el.offsetTop;
    var objParent = el.offsetParent;
    while (objParent.tagName.toUpperCase()!="BODY")
    {
        res["left"] += objParent.offsetLeft;
        res["top"] += objParent.offsetTop;
        objParent = objParent.offsetParent;
    }
    res["right"]=res["left"]+el.offsetWidth;
    res["bottom"]=res["top"]+el.offsetHeight;
    return res;
}

function hideElement(elName, Menu)
{
    if(BrVer!='E') return;
    for (i = 0; i < document.all.tags(elName).length; i++)
    {
        Obj = document.all.tags(elName)[i];
        if(!(pMenu=GetPos(Menu)))continue;
        if(!(pObj=GetPos(Obj)))continue;

        if(pObj["left"]<pMenu["right"] && pMenu["left"]<pObj["right"] && pObj["top"]<pMenu["bottom"] && pMenu["top"]<pObj["bottom"])
            Obj.style.visibility = "hidden";
    }
}

function showElement(elName)
{
    if(BrVer!='E') return;
    for (i = 0; i < document.all.tags(elName).length; i++)
    {
        obj = document.all.tags(elName)[i];
        if (!obj || !obj.offsetParent)continue;
        if(obj.style.visibility=="hidden")
            obj.style.visibility = "visible";
    }
}


© «Bitrix24», 2001-2024