Views: 15466
Last Modified: 08.10.2018
  • Highlighting of Links
  • How to Open a Menu Option in a New Window?
  • Displaying a Menu Option for Certain User Groups
  • Displaying a Menu Option to Unauthorized Users
  • Displaying a Menu Option when Visiting a Certain Site Section
  • Displaying Certain Options Only on the Home Page and in an Internal Section
  • Displaying a Menu Option Referring to a Specific Product Connected with the Product Opened on This Page
  • Pop Up Tips for Menu Options
  • How to Put Images Close to Menu Options?
  • Different Menu Option Images for Different Languages
  • Displaying of Customized Menu Different from Template Menu for Specific Site Sections
  • How to Keep Tree Menu Open at All Times?
  • Having Opened a Page through a Tree Menu, How to Prevent the Menu from Rolling Up and Make It Show on Which Page You Are?
  • Dropdown Menu with Inactive Options of the First Level
  • Hiding of a Side Menu According to the Page Properties
  • Menu and Cache

  • Kernel module version 9.0.5 in the bitrix:menu component has the parameter Delay building the menu template that permits adding menu options to the components.

     $GLOBALS['BX_MENU_CUSTOM']->AddItem('left', array('TEXT' => 'Mob.version', 'LINK' => $APPLICATION->GetCurPage(false) . '?mobile'))
    First parameter is the menu type.
    Second parameter is an array describing the menu option.


    Highlighting of Links

    The field Additional links to highlight in an extended editing form that permits you to include the highlighting of certain menu options when going to the page. It may be necessary when a user must not forget where they came from or in order to draw attention to a certain page.

    When visiting a page indicated in the field Additional links to highlight, the appropriate menu option will be highlighted. The path to pages is set starting from the site root.


    How to Open a Menu Option in a New Window?

    The following additional parameters must be indicated for the appropriate options in the extended editing mode:

    Name: target 
    Value: target="_blank"
    

    The code must be replaced in the menu template after displaying the menu element:

    <a href="<?=$arItem["LINK"]?>"><?=$arItem["TEXT"]?></a>
    

    with:

    <a href="<?=$arItem["LINK"]?>" <?=$arItem["PARAMS"]["target"]?>><?=$arItem["TEXT"]?></a>
    

    Displaying a Menu Option for Certain User Groups

    Choose the Condition type equal to For user group for the targeted option in the extended edit mode and select groups that will see this option in the Condition itself.

    Condition type: For user groups
    Condition: required_user_groups
    

    Displaying a Menu Option to Unauthorized Users

    Set the following condition in the extended edit mode:

    Condition type: PHP expression
    Condition: !$USER->IsAuthorized()
    

    Displaying a Menu Option when Visiting a Certain Site Section

    The system permits you to display a menu option only when visiting a specified site section or its pages. For this, select the option For file or folder in the field Condition type in the extended edit mode and specify the path in the Condition field.

    Note: The condition For file or folder should apply for static pages. It will not work on dynamic pages because it verifies the address and the dynamic pages always include selected values. For a dynamic URL, the use of the URL parameters condition is recommended.


    Displaying Certain Options Only on the Home Page and in an Internal Section

    Introduce the following php expression in the Condition field for the required options in extended mode:

    CSite::InDir('/about/') or CSite::InDir('/index.php')

    Displaying a Menu Option Referring to a Specific Product Connected with the Product Opened on This Page

    The URL parameters condition type may be used for this. The option will be displayed on pages with a defined parameter in a URL. The parameter works with a URL containing the symbol "?". I.e., with dynamic pages.

    The pages created on the basis of infoblocks have a URL of the following type: http://site/section/index.php?SECTION_ID=***. Let us assume that on the page with SECTION_ID=123 a menu option leading to the page SECTION_ID=456 must be displayed.

    We create a menu option leading to the page http://site/section/index.php?SECTION_ID=456. Let us select the URL parameter in the field Condition type and specify SECTION_ID in the first field and 123 in the second field.


    Pop Up Tips for Menu Options

    In the extended edit mode, add the additional parameter of A_TITLE and write the contents of the pop up tip there.

    Name: A_TITLE
    Value: pop_up_tip
    

    In the menu template:

    <?if($arItem["SELECTED"]):?>
    		<li><a href="<?=$arItem["LINK"]?>" class="selected"><?=$arItem["TEXT"]?></a></li>
    	<?else:?>
    		<li><a href="<?=$arItem["LINK"]?>"><?=$arItem["TEXT"]?></a></li>
    <?endif?>
    
    the first link in the code must be replaced with the line:
    <a href="<?=$arItem["LINK"]?>" class="selected" title="<?=$arItem["PARAMS"]["A_TITLE"]?>"><?=$arItem["TEXT"]?></a>
    
    and the second with:
    <a href="<?=$arItem["LINK"]?>" title="<?=$arItem["PARAMS"]["A_TITLE"]?>"><?=$arItem["TEXT"]?></a>
    

    How to Put Images Close to Menu Options?

    Add an additional parameter into the menu (menu editing in the extended mode), e.g., IMG, and write the address of the image that you want to display close to this option.

    Name: IMG
    Value: path_to_image
    

    In the following display of a menu element after the line (depending on the template):

    <a href="<?=$arItem["LINK"]?>">
    

    the following must be added in the menu template:

    <img src="<?=$arItem["PARAMS"]["IMG"]?>" border="0" />
    

    Different Menu Option Images for Different Languages

    The menu consists of image options set by CSS classes. The site is bilingual. The menu structure itself is already separated and connected; the external appearance must be separated.

    Solution:

    Specify the following in the menu template:
    <body class="lang-<?=LANG?>"> 
    
    in CSS:
    .menu li.item1 { 
    background-image:url(title-en.gif); 
    } 
    .lang-ru .menu li.item1 { 
    background-image:url(title-ru.gif); 
    }
    

    Displaying of Customized Menu Different from Template Menu for Specific Site Sections

    Such menu may be organized using a site template change (Control Panel > Settings > System settings > Websites > Websites, site edit, Template section, condition For file or folder). In addition, if the template is not complicated, verification may be set directly in the template code, and display the menus depending on a specific case:

    if($APPLICATION->GetCurPage() == "/index.php") {
    display of the menu for home page
    }
    else {
    display of the second menu
    }
    

    How to Keep Tree Menu Open at All Times?

    Solution:

    Take the standard template for tree menu and copy it into its template. After that, replace line 14 in the file template.php:
    <li class="close">
    
    with:
    <li>
    

    In this case, clicking the image will cause the unfolded options to hide.


    Having Opened a Page through a Tree Menu, How to Prevent the Menu from Rolling Up and Make It Show on Which Page You Are?

    Solution:

    Take the standard template for tree menu and copy it into its template. After that, replace line 14 in the file template.php:
    <li class="close">
    
    with:
    <li <?if (!$arItem["SELECTED"]):?>class="close"<?endif?>>
    

    Note: This solution works only up to the 2nd nesting level of the menu.

    The following code that must be introduced into the menu template file permits the menu from rolling up if the nesting level is higher than 2:

    ...
    <?if (!empty($arResult)):?>
    
    <?
    //analysis of open nodes of the tree
    $lastLevel = 0;
    $selected = false;
    
    foreach(array_reverse($arResult) as $arItem){
        if ($arItem["SELECTED"]) {
            $lastLevel = $arItem["DEPTH_LEVEL"];
            $selected = true;
        }
        if ($selected and $arItem["DEPTH_LEVEL"] < $lastLevel){
            $arResult[ $arItem["ITEM_INDEX"] ]["SELECTED"] = true;
            $lastLevel--;
        }
    }
    ?>
    
    <div class="menu-sitemap-tree">
    <ul>
    <?$previousLevel = 0;foreach($arResult as $arItem):?>
    ...
    

    Dropdown Menu with Inactive Options of the First Level

    The task is to ensure that after clicking an option of the main menu that has a dropdown menu of the second level, instead of going to that main menu option (this option must not be a link) the user goes to any of the second level options of the dropdown menu.

    If the main menu option has no second level menu, the user should go directly to that main menu option.

    To make it possible, all links must be eliminated from the menu display template code of the type:

    <?if ($arItem["DEPTH_LEVEL"] == 1):?>
             <a href="<?=$arItem["LINK"]?>" class="<?if ($arItem["SELECTED"]):?>root-item-selected<?else:?>root-item<?endif?>"><?=$arItem["TEXT"]?></a>
    

    The result is as follows:

    <?if ($arItem["DEPTH_LEVEL"] == 1):?>
             <li><?=$arItem["TEXT"]?></a>
    

    Hiding of a Side Menu According to the Page Properties

    Site template provides for the display of a side menu. This side menu must be hidden only on the pages with a specific property that cancels the display of a side menu.

    Solution:

    If the menu is located in the header, the function GetProperty may not be used because page properties are set after connection of the header. That is why the menu display may be “deferred” as follows:

    • Add the following code in the header where the menu is required:
    $APPLICATION->ShowProperty('menu');
    
    • In the page properties if the menu must be blocked:
    $APPLICATION->SetPageProperty('hide_menu', 'Y');
    
    • In the footer:
    if( 'Y' != $APPLICATION->GetPageProperty('hide_menu') ){
        ob_start();
        echo '<b>verification of the deferred menu!</b>';
        // ....here, the menu is displayed using a component or otherwise.... //
        $APPLICATION->SetPageProperty('menu', ob_get_clean() );
    }
    

    The menu itself is “displayed” in the footer if the hide_menu property value is not set to Y. It will not be actually displayed in the footer. Rather, it will go to the menu property in which the display can be “deferred” “higher” up the code using ShowProperty. If the menu is blocked, the property value of the menu will be empty, and the template will not display anything. If the menu is not blocked, the phrase “verification of the deferred menu!” will be displayed for this example (where $APPLICATION->ShowProperty('menu') is specified).


    Menu and cache

    Quote: I have ran out of the disk space completely. Took a look and it turned out, that the bitrix/managed_cache/MYSQL/menu folder's size is 16Gb! There are 2 menu at the site: horizontal - pagewise navigation and vertical - surfing via the catalog sections.

    Menu cache depends on the page URL. If the are many pages, the cache can be quite large as well. In this case, the more effective solution would be to disable cache in the component menu.



    Courses developed by Bitrix24