Skip to content

Instantly share code, notes, and snippets.

@EvilWolf
Created November 1, 2017 08:56
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 EvilWolf/be052e6a399aad667fb5172b84ecf765 to your computer and use it in GitHub Desktop.
Save EvilWolf/be052e6a399aad667fb5172b84ecf765 to your computer and use it in GitHub Desktop.
Простой шаблон mmenu для компонента menu в Битрикс
<? if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die(); ?>
<? if (!empty($arResult)): ?>
<nav id="mm-menu">
<ul class="navlist">
<?php
$lastDepth = 1;
foreach($arResult as $arItem):
if ($arItem['DEPTH_LEVEL'] > $arParams['MAX_LEVEL']) {
continue;
}
if ($arItem['DEPTH_LEVEL'] < $lastDepth) {
// Учитываем выход сразу из нескольких уровней
$levelDif = $arItem['DEPTH_LEVEL'] - $lastDepth;
echo str_repeat('</li></ul>', abs($levelDif));
$lastDepth += $levelDif;
}
$liClasses = '';
$linkClasses = '';
$isParent = false;
$isLastParent = ($arItem['DEPTH_LEVEL'] >= $arParams['MAX_LEVEL']);
if ($arItem['SELECTED']) {
$liClasses .= ' navlist-item__selected';
$linkClasses .= ' navlist-link__selected';
}
if ($arItem['IS_PARENT'] AND !$isLastParent) {
$liClasses .= ' navlist-item__parent';
$isParent = true;
}
?>
<li class="navlist-item <?= $liClasses ?>">
<a class="navlist-link <?= $linkClasses ?>" href="<?=$arItem["LINK"]?>"><?=$arItem["TEXT"]?></a>
<?php
if ($isParent) {
$lastDepth++;
echo '<ul class="navlist-sub">';
} else { ?>
</li>
<?php
}
?>
<?php
endforeach;
if ($lastDepth > 1) {
echo str_repeat('</li></ul>', $lastDepth - 1);
}
?>
</ul>
</nav>
<?php
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment