S
S
strangerfrompast2021-06-17 15:17:59
1C-Bitrix
strangerfrompast, 2021-06-17 15:17:59

How to add pictures to the Bitrix menu?

There is a lot of information on this issue, but outdated. The essence is below
It is necessary to add pictures in the menu of the online store catalog, which is formed from the ext.php file, which I set for each category in the admin panel through the catalog infoblock

Code of my ext.php menu

<?
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" => "1c_catalog",
    "IBLOCK_ID" => "5",
    "DEPTH_LEVEL" => "3",
    "CACHE_TYPE" => "A",
    "CACHE_TIME" => "3600",
  ),
  false
);
$aMenuLinks = array_merge($aMenuLinks, $aMenuLinksExt);
?>

I found on the forums how to draw a conclusion by adding the PICTURE parameter in 3 (or 4 places) to the component.php of the menu.sections component.

However, the problem arises at the moment where it says that in Bitrix:menu/themeMenu/template.php
must be inserted AFTER foreach($arResult as $arItem): code:

$strImg = '';
 
if(intval($arItem["PARAMS"]["PICTURE"])>0 && $arItem["DEPTH_LEVEL"]==1){
   $img = CFile::ResizeImageGet($arItem["PARAMS"]["PICTURE"], array('width'=>30, 'height'=>30),
 BX_RESIZE_IMAGE_PROPORTIONAL, false);  
   $strImg = '<img alt="" src="'.$img['src'].'" />';
 }


However, in the new builds of Bitrix there is not even a hint of foreach($arResult as $arItem):

Therefore, nothing works. Maybe someone faced the issue of displaying images for the catalog menu in the catalog.sections component?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yaroslav Alexandrov, 2021-06-18
@strangerfrompast

All data processing manipulations and changing (adding data) of the resulting menu array should be done in the result_modifier.php file
https://dev.1c-bitrix.ru/learning/course/index.php...
https://dev.1c -bitrix.ru/learning/course/index.php... For an
example of result_modifier.php for your task with pictures for each category, see the catalog_horizontal menu template, there is just a solution to questions with pictures and descriptions of categories. You can modify, I remember modifying pictures up to 4 levels of nesting.

A
Alexander, 2021-06-17
@idruweb

1) component.php cannot be changed in the Bitrix system components
2) look at what comes into the $arResult variable in template.php and add the necessary data there

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question