Skip to content

Instantly share code, notes, and snippets.

@EvilWolf
Created September 5, 2016 09:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save EvilWolf/0854b8ba4385326a3dfeb72951715e59 to your computer and use it in GitHub Desktop.
Список секций в news.list
<?php
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();
/* Собират секции элементов в отдельный массив результатов для news.list */
/* Можно использовать например для фильтрации по секциям в js */
$arSectionsByID = array();
foreach ($arResult['ITEMS'] as $arItem) {
if (!isset($arSectionsByID[$arItem['IBLOCK_SECTION_ID']]) OR !is_array($arSectionsByID[$arItem['IBLOCK_SECTION_ID']]))
$arSectionsByID[$arItem['IBLOCK_SECTION_ID']] = CIBlockSection::GetByID($arItem['IBLOCK_SECTION_ID'])->GetNext();
}
/* Сохраняем в кеш. */
$cp = $this->__component; // объект компонента
if (is_object($cp)) {
$arResult['SECTIONS_LIST'] = $arSectionsByID;
$cp->arResult['SECTIONS_LIST'] = $arSectionsByID;
$cp->SetResultCacheKeys(array('SECTIONS_LIST'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment