D
D
DeeUs2021-09-08 18:15:51
1C-Bitrix
DeeUs, 2021-09-08 18:15:51

How to display a list of sections and child elements?

Hello!
How to display a list of sections and child elements?
in this form:
section1
- element1
- element2
- element3
section2
- element1
- element2
- element3
, etc.

I have only one section element displayed:
section1
- element1
section2
- element1

code example

<?php
if (CModule::IncludeModule("iblock")){
  $iblock_id = 10;
  $arFilter = array(
    'ACTIVE' => 'Y',
    'IBLOCK_ID' => $iblock_id,
    'GLOBAL_ACTIVE'=>'Y',
  );
  $arSelect = array('IBLOCK_ID','ID','NAME');
  $arOrder = array('SORT'=>'ASC');
  $arSections = CIBlockSection::GetList($arOrder, $arFilter, false, $arSelect);
  while($arSection = $arSections->GetNext()){
    ?>
    <div class="faq_section">
      <div class="faq_section_title"><?=$arSection['NAME']?></div>
      <div class="faq_section_items">
        <?php
        $_arFilter = array(
          'ACTIVE' => 'Y',
          'IBLOCK_ID' => $iblock_id,
          'GLOBAL_ACTIVE'=>'Y',
          'SECTION_ID' => $arSection['ID']
        );
        $_arSelect = array('IBLOCK_ID','ID','NAME','DETAIL_TEXT');
        $arElements = CIBlockElement::GetList($arOrder, $_arFilter, false, $_arSelect);
        while($arElement = $arElements->GetNext()){
          ?>
          <div class="faq_item">
            <div class="question"><?=$arElement['NAME']?></div>
            <div class="answer"><?=$arElement['DETAIL_TEXT']?></div>
          </div>
          <?php
        }
        ?>
      </div>
    </div>
    <?php
  }
}
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yaroslav Alexandrov, 2021-09-09
@DeeUs

This is called receiving and processing data, grouping elements by section ID, i.e. PHP programming. This can be done in the result_modifier.php file, for example, the news.list or catalog.section component
https://dev.1c-bitrix.ru/learning/course/index.php...
https://dev.1c-bitrix.ru /learning/course/index.php... Form
your resulting array with the necessary keys, and then output in the required form in the component template

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question