A
A
Aleksander9112018-02-23 14:33:31
1C-Bitrix
Aleksander911, 2018-02-23 14:33:31

How to display icons of catalog menu items?

Good day everyone!
Happy Defender's Day everyone!
The question is. My catalog menu items are displayed automatically, i.e. the names of sections of the catalog itself are taken:
.catalog.menu.php .catalog.menu_ext.php
<? $aMenuLinks = Array(); ?>

<?
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();
global $APPLICATION;

   $aMenuLinksExt=$APPLICATION->IncludeComponent("bitrix:menu.sections", "", array(
   "IS_SEF" => "Y",
   "SEF_BASE_URL" => "/catalog/",
   "SECTION_PAGE_URL" => "#SECTION_CODE#/",
   "DETAIL_PAGE_URL" => "#SECTION_CODE#/#ELEMENT_CODE#",
   "IBLOCK_TYPE" => "catalog",
   "IBLOCK_ID" => "14", // ID - id вашего инфоблока
   "DEPTH_LEVEL" => "4",
   "CACHE_TYPE" => "A",
   "CACHE_TIME" => "0",
   "CACHE_TYPE" => "A",
   "CACHE_TIME" => "3600"
   ),
false
);
$aMenuLinks = array_merge($aMenuLinks, $aMenuLinksExt);
?>

output in section_horizontal.php
<?
      $APPLICATION->IncludeComponent(
    "bitrix:menu", 
    "menucat", 
    array(
      "ROOT_MENU_TYPE" => "catalog",
      "MENU_CACHE_TYPE" => "N",
      "MENU_CACHE_TIME" => "3600",
      "MENU_CACHE_USE_GROUPS" => "Y",
      "MENU_CACHE_GET_VARS" => array(
      ),
      "MAX_LEVEL" => "4",
      "CHILD_MENU_TYPE" => "catalog",
      "USE_EXT" => "Y",
      "DELAY" => "N",
      "ALLOW_MULTI_SELECT" => "Y",
      "COMPONENT_TEMPLATE" => "menucat"
    ),
    false
  );
      ?>

And I created my own template for this very menu.
Such a menu does not automatically create a file, something like:
<?
$aMenuLinks = Array(
  Array(
    "Каталог товаров", 
    "/shop/catalog/", 
    Array(), 
    Array(), 
    "false" 
  ),
  Array(
    "Ремонт и сервис", 
    "/service/", 
    Array(), 
    Array(), 
    "" 
  ),
 и тд
?>

in which you can set the IMG parameter and display icons for menu items.
How can I display icons in such a menu? Maybe there is some option through Additional fields or some other way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Nikolaev, 2018-02-23
@Aleksander911

It seemed clear enough to me.
1) Copy the bitrix:menu.sections component to its own namespace.
2) We make changes to the copied component
2.1) Approximately on line 45 in CIBlockSection::GetList we add an image to select and in the while block we check - if there is an image - we get its url, if not - we prescribe the url to the load
2.2) approximately on line 128 , to block:

$aMenuLinksNew[$menuIndex++] = array(
  htmlspecialcharsbx($arSection["~NAME"]),
  $arSection["~SECTION_PAGE_URL"],
  $arResult["ELEMENT_LINKS"][$arSection["ID"]],
  array(
    "FROM_IBLOCK" => true,
    "IS_PARENT" => false,
    "DEPTH_LEVEL" => $arSection["DEPTH_LEVEL"],
  ),
);

Along with the FROM_IBLOCK, IS_PARENT parameters, we add our own parameter. For example, IMAGE_PATH, where we enter the image from 2.1
3) In .catalog.menu_ext.php we replace the call with our component
4) In the menucat template of the bitrix:menu component, we check the parameter and work with it.
As an example - you can see the question of the same toaster: How to add your own classes to all bitrix menu items?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question