GetIBlockElement
array GetIBlockElement( int ID, string type = "" );
The function returns an information block element by its ID.
Parameters
Parameter | Description |
---|---|
ID | Element ID. |
type | Type of an element. Specified in the module settings. If present, the selected element is checked to match this type. Optional. By default, no restrictions applied. |
Return Values
The function returns an array of the information block fields and the following fields:
- IBLOCK_NAME - information block name;
- PROPERTIES - array of property values. Has property symbolic codes as indices (specified in the information block settings). If the code is not specified, the unique ID of a property is used.
Value of each property is an array of the following format:
Array( "NAME" => "property name", "DEFAULT_VALUE" => "default property value", "VALUE" => "property value or an array of values for multiple property sets", "VALUE_ENUM_ID" => "ID of the property value for the type LIST" )
If no element can be found, the function returns false.
Remarks
Variables #SITE_DIR#
, #IBLOCK_ID#
, #EXTERNAL_ID#
and #ID#
are replaced with their corresponding values
(fields LIST_PAGE_URL and DETAIL_PAGE_URL). If no block is found, false
is returned.
See Also
Example
<? require($_SERVER['DOCUMENT_ROOT'].'/bitrix/header.php'); $APPLICATION->SetTitle('Product description'); // include the module and select the element of the type product by its ID $arIBlockElement = false; if (CModule::IncludeModule('iblock') && ($arIBlockElement = GetIBlockElement($ID, 'product'))) { // set the page title according to the element name $APPLICATION->SetTitle($arIBlockElement['NAME']); // add title to the navigation chain; make it a link to the current information block $APPLICATION->AddChainItem($arIBlockElement['IBLOCK_NAME'], 'products.php?ID='.$arIBlockElement['IBLOCK_ID']); // show the detailed image echo ShowImage($arIBlockElement['DETAIL_PICTURE'], 150, 150, 'border="0"', '', true); // render the detailed description echo $arIBlockElement['DETAIL_TEXT'].'<br>'; // render the PRICE property echo $arIBlockElement['PROPERTIES']['PRICE']['VALUE'].'<br>'; // display the other properties $arProps = $arIBlockElement['PROPERTIES']; foreach($arProps as $property_code=>$arValue) { // skip if the property value is empty of the property name is PRICE if ($property_code=='PRICE' || (!is_array($arValue['VALUE']) && strlen($arValue['VALUE'])<=0) || (is_array($arValue['VALUE']) && count($arValue['VALUE'])<=0) ) continue; // display a pair "Name:Value" if(!is_array($arValue['VALUE'])) echo $arValue['NAME'].": ".$arValue['VALUE']; else { echo $arValue['NAME'].': '; foreach($arValue['VALUE'] as $val) { echo $val.'<br>'; } } } } else echo ShowError('Cannot find element'); require($_SERVER["DOCUMENT_ROOT"].'/bitrix/footer.php"); ?>
© «Bitrix24», 2001-2024