Last active
May 15, 2024 15:15
-
-
Save gdecider/8722b349460e43707b82460951c00757 to your computer and use it in GitHub Desktop.
Битрикс Ш меню многоуровневое (простая разметка, рекурсивный вывод)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? $APPLICATION->IncludeComponent("bitrix:menu", "menu-template", Array( | |
"ALLOW_MULTI_SELECT" => "N", // Разрешить несколько активных пунктов одновременно | |
"CHILD_MENU_TYPE" => "catalog", // Тип меню для остальных уровней | |
"DELAY" => "N", // Откладывать выполнение шаблона меню | |
"MAX_LEVEL" => "4", // Уровень вложенности меню | |
"MENU_CACHE_GET_VARS" => array( // Значимые переменные запроса | |
0 => "", | |
), | |
"MENU_CACHE_TIME" => "3600", // Время кеширования (сек.) | |
"MENU_CACHE_TYPE" => "N", // Тип кеширования | |
"MENU_CACHE_USE_GROUPS" => "Y", // Учитывать права доступа | |
"ROOT_MENU_TYPE" => "catalog", // Тип меню для первого уровня | |
"USE_EXT" => "Y", // Подключать файлы с именами вида .тип_меню.menu_ext.php | |
), | |
false | |
); ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die(); | |
/** @var array $arResult */ | |
$parents = []; | |
foreach ($arResult as $index => $item) { | |
if ($item['IS_PARENT']) { | |
$parents[$item['DEPTH_LEVEL']] = &$arResult[$index]; | |
} | |
if ($item['DEPTH_LEVEL'] > 1) { | |
$parents[$item['DEPTH_LEVEL'] - 1]['SUB'][] = &$arResult[$index]; | |
unset($arResult[$index]); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die(); | |
/** @var array $arResult */ | |
/** | |
* Рекурсивный вывод меню | |
* @param array $items | |
*/ | |
function showLevel($items) | |
{ | |
if (empty($items)) { | |
return; | |
} | |
echo "<ul>"; | |
foreach ($items as $item) { | |
$cssClasses = [ | |
"level-{$item['DEPTH_LEVEL']}", | |
]; | |
if ($item["PERMISSION"] <= "D") { | |
continue; | |
} | |
if ($item["IS_PARENT"]) { | |
$cssClasses[] = 'parent'; | |
} | |
if ($item["SELECTED"]) { | |
$cssClasses[] = 'active'; | |
} | |
$strClasses = implode(' ', $cssClasses); | |
echo "<li>"; | |
echo "<a class=\"{$strClasses}\" href=\"{$item['LINK']}\">{$item['TEXT']}</a>"; | |
if (!empty($item['SUB'])) { | |
showLevel($item['SUB']); | |
} | |
echo "</li>"; | |
} | |
echo "</ul>"; | |
} | |
showLevel($arResult); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment