Skip to content

Instantly share code, notes, and snippets.

@livevasiliy
Last active August 11, 2019 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save livevasiliy/ddb7a0200a317a9235ce2d8e1b5a9108 to your computer and use it in GitHub Desktop.
Save livevasiliy/ddb7a0200a317a9235ce2d8e1b5a9108 to your computer and use it in GitHub Desktop.
Многоуровневое меню для Битрикс на Bootstrap 4
<?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?>
<?if (!empty($arResult)):?>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="nav navbar-nav">
<?
$previousLevel = 0;
foreach($arResult as $arItem):?>
<?if ($previousLevel && $arItem["DEPTH_LEVEL"] < $previousLevel):?>
<?=str_repeat("</ul></li>", ($previousLevel - $arItem["DEPTH_LEVEL"]));?>
<?endif?>
<?if ($arItem["IS_PARENT"]):?>
<?if ($arItem["DEPTH_LEVEL"] == 1):?>
<li class="nav-item dropdown">
<a
href="<?if($arItem['LINK']['$str']!='p'){echo '#';}?>"
class="<?if ($arItem["SELECTED"]):?>active<?else:?>nav-link dropdown-toggle text-white<?endif?>"
data-toggle="dropdown"
role="button"
aria-expanded="false"
>
<?=$arItem["TEXT"]?>
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<?else:?>
<li <?if ($arItem["SELECTED"]):?> class="item-selected"<?endif?>>
<a href="<?=$arItem["LINK"]?>" class="parent"><?=$arItem["TEXT"]?></a>
<ul>
<?endif?>
<?else:?>
<?if ($arItem["PERMISSION"] > "D"):?>
<?if ($arItem["DEPTH_LEVEL"] == 1):?>
<li class="nav-item">
<a
href="<?=$arItem["LINK"]?>"
class="nav-link text-white <?if ($arItem["SELECTED"]):?>root-item-selected<?else:?>root-item<?endif?>"
>
<?=$arItem["TEXT"]?>
</a>
</li>
<?else:?>
<a class="dropdown-item" href="<?=$arItem["LINK"]?>">
<?=$arItem["TEXT"]?>
</a>
<?endif?>
<?else:?>
<?if ($arItem["DEPTH_LEVEL"] == 1):?>
<li>
<a
href=""
class="<?if ($arItem["SELECTED"]):?>root-item-selected<?else:?>root-item<?endif?>"
title="<?=GetMessage("MENU_ITEM_ACCESS_DENIED")?>"
>
<?=$arItem["TEXT"]?>
</a>
</li>
<?else:?>
<li style="padding: 5px 0 5px 0px;">
<a
href=""
class="denied"
title="<?=GetMessage("MENU_ITEM_ACCESS_DENIED")?>"
>
<?=$arItem["TEXT"]?>
</a>
</li>
<?endif?>
<?endif?>
<?endif?>
<?$previousLevel = $arItem["DEPTH_LEVEL"];?>
<?endforeach?>
<?if ($previousLevel > 1)://close last item tags?>
<?=str_repeat("</ul></li>", ($previousLevel-1) );?>
<?endif?>
</ul>
</div>
</nav>
<?endif?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment