Заполняем массив $sects:
<?Выводим меню:
$arResult['SECTION_ID'] = CIBlockFindTools::GetSectionID(
$arResult['VARIABLES']['SECTION_ID'], // ID текущего раздела
$arResult['VARIABLES']['SECTION_CODE'], //код текущего раздела (нам он не понадобится, но пусть будет)
array('IBLOCK_ID' => $arParams['IBLOCK_ID'])
);
$sects = [];
$CurDir = $APPLICATION->GetCurDir();
$list = CIBlockSection::GetNavChain(false, $arResult['SECTION_ID'], ['ID', 'NAME', 'SECTION_PAGE_URL', 'DEPTH_LEVEL', 'RIGHT_MARGIN', 'LEFT_MARGIN'], true);
foreach ($list as $v) {
$res = CIBlockSection::GetByID($v['ID']);
if($ar_res = $res->GetNext()) {
$sects[$v['ID']]['SECTION_PAGE_URL'] = $ar_res['SECTION_PAGE_URL'];
$sects[$v['ID']]['PARENT'] = $v['IBLOCK_SECTION_ID'];
}
$sects[$v['ID']]['DEPTH_LEVEL'] = $v['DEPTH_LEVEL'];
$sects[$v['ID']]['NAME'] = $v['NAME'];
$sects[$v['ID']]['RIGHT_MARGIN'] = $v['RIGHT_MARGIN'];
$sects[$v['ID']]['LEFT_MARGIN'] = $v['LEFT_MARGIN'];
}
?>
<ul class="left-menu">
<?
foreach ($sects as $k => $sect) {?>
<?if($sect["RIGHT_MARGIN"] - $sect["LEFT_MARGIN"] != 1):?>
<li class="sect_<?=$sect['DEPTH_LEVEL']?>">
<?if($CurDir != $sect['SECTION_PAGE_URL']):?>
<i class="svg inline" aria-hidden="true"><svg width="7" height="5"><use xlink:href="/local/templates/template/images/svg/arrows.svg?1722857343#down-7-5"></use></svg></i>
<?endif;?>
<a<?if($CurDir == $sect['SECTION_PAGE_URL']):?> class="selected"<?endif;?> href="<?=$sect['SECTION_PAGE_URL']?>" data-id=<?=$k?>><?=$sect['NAME']?></a>
</li>
<?endif;?>
<?}
if($sects[$arResult['VARIABLES']["SECTION_ID"]]["RIGHT_MARGIN"] - $sects[$arResult['VARIABLES']["SECTION_ID"]]["LEFT_MARGIN"] == 1) {
//фильтру указываем ID раздела и ID его инфоблока
$arFilter = array('SECTION_ID' => $sects[$arResult['VARIABLES']["SECTION_ID"]]["PARENT"], 'IBLOCK_ID' => $arParams['IBLOCK_ID'], 'ACTIVE' => 'Y');
$rsSect = CIBlockSection::GetList(Array("SORT"=>"ASC"),$arFilter, false, array('ID', 'NAME', 'SECTION_PAGE_URL'));
} else {
//фильтру указываем ID раздела и ID его инфоблока
$arFilter = array('SECTION_ID' => $arResult['VARIABLES']["SECTION_ID"], 'IBLOCK_ID' => $arParams['IBLOCK_ID'], 'ACTIVE' => 'Y');
$rsSect = CIBlockSection::GetList(Array("SORT"=>"ASC"),$arFilter, false, array('ID', 'NAME', 'SECTION_PAGE_URL'));
}
?>
<?while ($arSect = $rsSect->GetNext()) {?>
<li class='child'><a<?if($CurDir == $arSect['SECTION_PAGE_URL']):?> class="selected"<?endif;?> href='<?=$arSect["SECTION_PAGE_URL"]?>'><?=$arSect["NAME"]?></a></li>
<?}
?>
</ul>