N
N
Nadezhda Golovina2020-09-02 15:38:24
1C-Bitrix
Nadezhda Golovina, 2020-09-02 15:38:24

How to display your classes for the top menu item and sub-items of Bitrix?

Hello. There is a top menu template:

<?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><a href="<?=$arItem["LINK"]?>" <?if ($arItem["SELECTED"]):?>class="active"<?endif?>><?=$arItem["TEXT"]?><i class="fa fa-chevron-down color_text" aria-hidden="true"></i></a>
        <ul>
    <?else:?>
      <li><a href="<?=$arItem["LINK"]?>" class="parent"><?=$arItem["TEXT"]?><i class="fa fa-chevron-right" aria-hidden="true"></i></a>
        <ul>
    <?endif?>

  <?else:?>

    <?if ($arItem["PERMISSION"] > "D"):?>

      <?if ($arItem["DEPTH_LEVEL"] == 1):?>
        <li><a href="<?=$arItem["LINK"]?>" class="<?if ($arItem["SELECTED"]):?>active<?endif?>"><?=$arItem["TEXT"]?></a></li>
      <?else:?>
                <li<?if ($arItem["SELECTED"]):?> class="item-selected"<?endif?>><a href="<?=$arItem["LINK"]?>"><?=$arItem["TEXT"]?></a></li>
      <?endif?>

    <?else:?>

      <?if ($arItem["DEPTH_LEVEL"] == 1):?>
        <li><a href="" class="<?if ($arItem["SELECTED"]):?>active<?endif?>" title="<?=GetMessage("MENU_ITEM_ACCESS_DENIED")?>"><?=$arItem["TEXT"]?></a></li>
      <?else:?>
        <li><a href="" class="denied" title="<?=GetMessage("MENU_ITEM_ACCESS_DENIED")?>"><?=$arItem["TEXT"]?></a></li>
      <?endif?>

    <?endif?>

  <?endif?>

It is necessary to add a class to a specific item. And more classes to its subparagraphs.
The option with an additional class to "parent" does not work for some reason:
<a href="<?=$arItem["LINK"]?>" class="parent <?=$arItem["PARAMS"]["dif_class"]?>"><?=$arItem["TEXT"]?><i class="fa fa-chevron-right" aria-hidden="true"></i></a>

The menu template says:
Array(
    "Пункт меню (с выпадающим списком)", 
    "/sales/", 
    Array("/link1/"), 
    Array("dif_class"=>"buster-top", "FROM_IBLOCK"=>"1", "IS_PARENT"=>"1", "DEPTH_LEVEL"=>"1"), 
    "" 
  ),

Screenshot of a menu item in the extended mode in the admin panel
5f4fa6635a8fa204185891.jpeg
Question: How can you still display your class in the necessary items and sub-items of Bitrix?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question