Answer the question
In order to leave comments, you need to log in
Bitrix catalog.section how to display sections and elements?
It is necessary to display the elements sorted by sections on one page.
For example: Section 1{Element1, Element2, Element3}, then on the same page below Section 2{Element1, element2, element3}, etc.
Through result_modifer I was able to get the section name for each element:
foreach ($arResult['ITEMS'] as $key => $arItem)
{
$arSectionList = array();
$rsSections = CIBlockElement::GetElementGroups($arItem['ID']);
while ($arSection = $rsSections->Fetch())
{
$arSectionList[] = array(
'ID' => $arSection['ID'],
'NAME' => $arSection['NAME'],
);
}
$arItem['SECTION_NAME'
$arResult['ITEMS'][$key] = $arItem;
}
Now I want to collect an array of the form Section 1{Element1, Element2, Element3}. Suggest a solution.
Answer the question
In order to leave comments, you need to log in
Request in a loop - ah-ah-ah, how bad.
And in general, right here for this solution:
foreach ($arResult['ITEMS'] as $key => $arItem) {
$arSectionList = array();
$rsSections = CIBlockElement::GetElementGroups($arItem['ID']);
while ($arSection = $rsSections->Fetch())
{
$arSectionList[] = array(
'ID' => $arSection['ID'],
'NAME' => $arSection['NAME'],
);
$arResult['ITEMS_BY_GROUP'][$arSection['ID']][] = $key;
}
$arItem['SECTION_NAME'] = $arSectionList;
$arResult['ITEMS'][$key] = $arItem;
}
once stumbled across the open spaces. I took it for myself, sometimes I redo it)
https://github.com/Rad1calDreamer/bitrix.article.list
here is both a component and a base template
The easiest way, "on the forehead":
If the directory is small (<1000), then select all sections from the beginning.
Next, iterate over the resulting array of sections and for each section select all the elements belonging to it
- but there will be a huge number of extra requests. You can get by with two:
1. select all sections of CIBlockSection::GetTreeList()
2. select all elements of CIBlockElement::GetList()
3. combine two arrays into one.
If you mentioned result_modifer, then you are using some component, most likely it is either news.list or catalog.section. It's easier to write your own than to remake a finished one.
Does the bitrix:catalog.sections.top component do the wrong thing? We specify a number with a large margin for the top elements and that's it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question