How to Retrieve All Section Fields, Including Custom Fields, in section.php
If you need information about the current section that is missing from the original array, you can use CIBlockFindTools::GetSectionID. This method retrieves the current section ID.
Once we know the section ID, we can use CIBlockSection::GetList to retrieve the required section information, including custom fields. List the fields you need in $arSelect and store the retrieved information in variables.
Back to blog
$arResult['SECTION_ID'] = CIBlockFindTools::GetSectionID(
$arResult['VARIABLES']['SECTION_ID'],
$arResult['VARIABLES']['SECTION_CODE'],
array('IBLOCK_ID' => $arParams['IBLOCK_ID'])
);
Using CIBlockFindTools::GetSectionID, we can store the current section ID in $arResult['SECTION_ID'].Once we know the section ID, we can use CIBlockSection::GetList to retrieve the required section information, including custom fields. List the fields you need in $arSelect and store the retrieved information in variables.
$arSelect = array(
'NAME',
'DESCRIPTION',
'PICTURE',
'UF_*' // все пользовательские поля, можно перечислять конкретные
);
$sectionResult = CIBlockSection::GetList(
false,
array(
"IBLOCK_ID" => $arParams["IBLOCK_ID"],
"ID" => $arResult["SECTION_ID"]
),
false,
$arSelect
);
while ($sectionProp = $sectionResult->GetNext()) {
$sectDescript = $sectionProp['DESCRIPTION']; // Описание раздела
$sectPict = $sectionProp['PICTURE']; // Картинка раздела
$ufLink = $sectionProp['~UF_LINK']; // Пользователькое поле с кодом UF_LINK- в html формате
$ufText = $sectionProp['UF_TEXT']; // Пользователькое поле с кодом UF_TEXT
}
These variables can then be used anywhere in section.php, checking that they exist and are not empty to ensure the code works correctly.
//Картинка (с уменьшением)
if (!empty($sectPict)) {
$renderImageSect = CFile::ResizeImageGet($sectPict, Array("width" => '1200', "height" => '400'), BX_RESIZE_IMAGE_EXACT);
echo $renderImageSect['src']
}
//Описание
if (!empty($sectDescript)) {
echo $sectDescript;
}