A
A
Andrey Bely2020-02-21 10:06:58
1C-Bitrix
Andrey Bely, 2020-02-21 10:06:58

Bitrix. How to make a menu of this type?

Good morning.
It is necessary to implement a menu based on brands (the brand is a subsection in the infoblock) and that these brands are filtered alphabetically (by the first character in the name of the brand itself). The whole thing should be loaded into the menu automatically, i.e. if a new subsection was added to the infoblock and, for example, it was named “Company”, then the letter “C” should appear, if it was not there, and when hovering over it, this “Company” section should appear in the drop-down list.
I can't even imagine how to implement this, please help.
5e4f819025b32948473622.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
smilingcheater, 2020-02-21
@just_guy95

Through menu.ext. Official dock - https ://dev.1c-bitrix.ru/learning/course/index.php...
a list of menu items by found letters, something like this:

$bxSection = new CIBlockSection();
$res = $bxSection->GetList(...);

$letters = [];
while ($section = $res->Fetch()) {
    $letter = mb_substr($section['NAME'], 0, 1);
    if (empty($letter)) continue;
    
    if (empty($letters[$letter])) {
        $letters[$letter] = [
            'LETTER' => $letter,
            'SECTIONS' => []
        ];
    }

    $letters[$letter]['SECTIONS'][] = $section;
}

ksort($letters);

foreach ($letters as $letter) {
    $aMenuLinksExt[] = [
        $letter['LETTER'],
        '', // Ссылка, если нужна для самой буквы
        [],
        [
            'SECTIONS' => $letter['SECTIONS'], // Массив подразделов-брендов
        ],
    ];
}

then, in the output template of this menu, process the sub-items that came in $arItem['SECTIONS']
(not sure if the code is 100% correct, wrote blindly)

Y
Yaroslav Alexandrov, 2020-02-21
@alexyarik

Here is an example of a menu on the infoblock, only instead of elements you get sections, with the PHP function you get the first letter for the name
https://phpjs.ru/2019/04/26/bitrix-%D1%8D%D0%BB%D0...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question