K
K
kaidos2022-03-27 13:12:36
1C-Bitrix
kaidos, 2022-03-27 13:12:36

How to check for a submenu in Bitrix?

It is necessary for me if the menu has a submenu to interpose other code of an output of item'ov of the menu.
Output of menu items:

<?php if(!empty($arResult)): ?>

<div class="nav__menu">

  <?php foreach($arResult as $item): ?>

    <?if($item["SELECTED"]):?>
      <a href="<?= $item['LINK'] ?>" class="menu__item menu__item--active"><?= $item['TEXT'] ?></a>
    <?else:?>
      <a href="<?= $item['LINK'] ?>" class="menu__item"><?= $item['TEXT'] ?></a>
    <?endif;?>

  <?php endforeach; ?>

</div>

<?php endif; ?>


If there is a submenu, then the main item should have a ul tag instead of a.
Instead of the a tag:

<ul class="menu__item menu__item--active">

  <?if($item["SELECTED"]):?>
    <a href="<?= $item['LINK'] ?>" class="menu__item menu__item--active"><?= $item['TEXT'] ?></a>
  <?else:?>
    <a href="<?= $item['LINK'] ?>" class="menu__item"><?= $item['TEXT'] ?></a>
  <?endif;?>
  
  <?php if (!empty($item['subitems'])): ?>

    <?php foreach ($item['subitems'] as $subitem): ?>

    <div class="menu__item__list">

      <?if($subitem["SELECTED"]):?>
        <a href="<?= $subitem['LINK']; ?>" class="item__list item__list--active"><?= $subitem['TEXT'] ?? ''; ?></a>
      <?else:?>
        <a href="<?= $subitem['LINK']; ?>" class="item__list"><?= $subitem['TEXT'] ?? ''; ?></a>
      <?endif;?>

    </div>

    <?php endforeach; ?>
    
  <?php endif; ?>

</ul>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2022-03-29
@Firsov36

if($item["DEPTH_LEVEL"] > 1) { ... }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question