Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Простой шаблон 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
You can’t perform that action at this time.