P
P
photosho2019-07-02 10:27:14
1C-Bitrix
photosho, 2019-07-02 10:27:14

What is the best way to implement a submenu with a division into "categories"?

There is a dropdown menu built so that the main menu file is called ".top.menu.php" and the dropdown file is called ".left.menu.php", which is created in each section and contains a list of the dropdown menu items for that section .
There was a task to divide the items of the drop-down menu into "categories". That is, on top - the title (not a link, but just a visual design for the user), and below it - the menu items related to this "category"; further, right there - a new title and other menu items.
How would it be better to implement this from the position of Bitrix? There is such an option: create "categories" using empty items (without a link), perhaps pass some additional parameter with them to the array. In the template, when outputting, when you meet such an item, you create special markup for it, as for a heading. Would it be correct to implement it this way or is there another better way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kudis, 2019-07-02
@kudis

Use the `.left.menu_ext.php` file inside the section.
Don't forget to allow it to be used in the menu "USE_EXT" => "Y"
; the file itself will look something like this:

use Bitrix\Main\Loader,
    Bitrix\Main\LoaderException;

try {
    if (!Loader::includeModule('iblock')) {
        return;
    }
} catch (LoaderException $e) {
    return;
}

$obItems = CIBlockElement::getList(
    [
        'SORT' => 'asc',
        'NAME' => 'asc'
    ],
    [
        'IBLOCK_TYPE' => 'type',
        'IBLOCK_CODE' => 'iblockcode',
        'ACTIVE' => 'Y'
    ],
    false,
    false,
    [
        'ID',
        'CODE',
        'NAME',
    ]
);

$aMenuLinksExt = [];

while ($arItem = $obItems->fetch()) {
    $aMenuLinksExt[] = [
        $arItem['NAME'],
        $arItem['CODE'] . '/',
        [],
        [],
        ''
    ];
}

$aMenuLinks = array_merge($aMenuLinks, $aMenuLinksExt);

here, infoblock elements are added to the left menu.
You can add sections.
For a menu template, you can pass the parameter through the 4th element of the array (For example: UNCLICKABLE)
$aMenuLinksExt[] = [
        $arItem['NAME'],
        $arItem['CODE'] . '/',
        [],
        ['UNCLICKABLE' => true],
        ''
    ];

In the `$arResult` of the menu template, this parameter will come in the `'PARAMS'` array

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question