U
U
UnderDog322020-06-25 09:05:33
1C-Bitrix
UnderDog32, 2020-06-25 09:05:33

How to get the value of an element property by ID in Bitrix?

There is an infoblock with ID 5 .
It has an element with ID 371 .
You need to get the values ​​of the slogan and copy properties .
The data will be displayed in the footer of the site, in the footer.php file.

The following construction does not output anything:

<?
  $res = CIBlockElement::GetByID($_GET["371"]);
  if($ar_res = $res->GetNext())
  echo $ar_res['PROPERTIES']['slogan']['VALUE'];
  echo $ar_res['PROPERTIES']['copy']['VALUE'];
?>


How to write code correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Nikolaev, 2020-06-25
@UnderDog32

The GetByID method does not return the element's properties, but is a simple getList layer that queries all the properties.
Explicitly use CIblockElement::getList to get properties

$resElement = \CIBlockElement::GetList(
    [],
    [
        'IBLOCK_ID' => 5,
        'ID' => 371,
    ],
    false,
    false,
    [
        'ID',
        'IBLOCK_ID',
        'PROPERTY_SLOGAN',
        'PROPERTY_COPY'
    ]
);

if ( !($element = $resElement->getNext() ) )
{
    echo "Элемент не найден";
    return;
}

var_dump($element);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question