A
A
alexander_chn2018-04-30 15:12:57
1C-Bitrix
alexander_chn, 2018-04-30 15:12:57

How to display additional images of an infoblock element through Bitrix API?

Hello! It is necessary to display additional images of the infoblock element using api bitrix. There are multiple properties like File ATT_OW_MORE_PHOTO
The code below outputs these images, but strangely, if there are three additional images. then it will display both the id and the name and the detailed text three times, how to rewrite it so that it is displayed normally:

<?
      $iblock_id = 10;
      $arSelect = Array("ID", "NAME", "PROPERTY_ATT_OW_MORE_PHOTO", "DETAIL_PICTURE", "DETAIL_TEXT");
      $arFilter = Array( "IBLOCK_ID"=>$iblock_id, "ACTIVE_DATE"=>"Y", "ACTIVE"=>"Y" );
      $res = CIBlockElement::GetList(Array("SORT"=>"ASC"), $arFilter, false, false, $arSelect);

      while($ob = $res->GetNextElement()) :
        $arFields = $ob->GetFields();

        echo "ID: " . $arFields['ID'];echo "<br>";

        $db_old_groups = CIBlockElement::GetElementGroups($arFields['ID'], true);
        // while($ar_group = $db_old_groups->Fetch())
        // 	echo "SECTION CODE: " . $ar_group["CODE"]." ";
        echo "<br>";
        echo "NAME: " . $arFields['NAME'];echo "<br>";
        echo "PICTURE: ".CFile::GetPath($arFields['DETAIL_PICTURE']);echo "<br>";
        echo "DETAIL TEXT" . $arFields['DETAIL_TEXT'];echo "<br>";
        
        echo "dop photo: ";

        echo "<img src='" . CFile::GetPath($arFields['PROPERTY_ATT_OW_MORE_PHOTO_VALUE']) . "' />";
        echo "<br>===================<br>";

      endwhile;
      ?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
den-masonov, 2018-04-30
@den-masonov

the getlist output should also contain additional properties in the form of an array ["PROPERTIES"]["ATT_OW_MORE_PHOTO"]
take it and run it through the loop

A
alexander_chn, 2018-05-01
@alexander_chn

Decided like this:

<?
      $iblock_id = 10;
      $arSelect = Array("ID", "NAME", "CODE", "PROPERTY_ATT_OW_MORE_PHOTO", "DETAIL_PICTURE", "DETAIL_TEXT");
      $arFilter = Array( "IBLOCK_ID"=>$iblock_id, "ACTIVE_DATE"=>"Y", "ACTIVE"=>"Y" );
      $res = CIBlockElement::GetList(Array("SORT"=>"ASC"), $arFilter, false, false, $arSelect);

      $code = "";
      while($ob = $res->GetNextElement()) :
        $arFields = $ob->GetFields();

        if ($code != $arFields['CODE']) {

          $code = $arFields['CODE'];
          echo "ID: " . $arFields['ID'];echo "<br>";

          $db_old_groups = CIBlockElement::GetElementGroups($arFields['ID'], true);
          while($ar_group = $db_old_groups->Fetch())
            echo "SECTION CODE: " . $ar_group["CODE"]." ";
          echo "<br>";
          echo "NAME: " . $arFields['NAME'];echo "<br>";
          echo "CODE: " . $arFields['CODE'];echo "<br>";
          echo "PICTURE: "."<img width='250px' src='" . CFile::GetPath($arFields['DETAIL_PICTURE']) . "'/>";
          echo "<br>";
          echo "DETAIL TEXT: " . $arFields['DETAIL_TEXT'];echo "<br>";
        }
        echo "<img width='250px' src='" . CFile::GetPath($arFields['PROPERTY_ATT_OW_MORE_PHOTO_VALUE']) . "'/>";
      endwhile;
      unset($iblock_id, $arSelect, $arFilter, $res, $code, $ob, $arFields, $db_old_groups);
      ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question