D
D
Dmitry Grabko2017-09-08 18:23:27
PHP
Dmitry Grabko, 2017-09-08 18:23:27

How to get the value of a custom field of file type?

For sections, I added a file type field: UF_LOGO_MANUFACTURE In the catalog
catalog.element complex component template, I add:

<?foreach ($arResult["UF_LOGO_MANUFACTURE"] as $EX):?>
                               <?
                                   $arFile = CFile::GetFileArray($EX);
                           //print_r($arFile);
                               ?>
                               <?$renderImage = CFile::ResizeImageGet($arFile, Array("width" => 820, "height" => 523), BX_RESIZE_IMAGE_EXACT);?>
                                <img src="<?=$renderImage['src']?>" alt="Слайд" width="820" height="523">
                        <?endforeach?>

But there is no result. I tried all the solutions that I found on Google, but the value does not get into the array. Where is the mistake?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
I'm Yoda, 2017-09-13
@Anadi

Does $arResult have a UF_LOGO_MANUFACTURE field at all? First you need to get a custom field. For example like this:

$arFilter = array(
  'IBLOCK_ID' => $arResult['IBLOCK_ID'],
  'ID' => $arResult['IBLOCK_SECTION_ID'],
);
$arSelect = array('ID','UF_*');
$res = CIBlockSection::GetList(array(), $arFilter, false, $arSelect);
if($ar_logos = $res->GetNext())
  $arLogo = $ar_logos;

Then output as you please:
<?if(!empty($arLogo['UF_LOGO_MANUFACTURE'])):{?>
      <?foreach($arLogo['UF_LOGO_MANUFACTURE'] as $arLogoID):?>
        if(empty($arLogoID)) break;

        $arFile[$arLogoID] = CFile::GetFileArray($arLogoID);

        // Ресайзим если надо
        $arFileTmp = CFile::ResizeImageGet(
          $arLogoID,
          array("width" => 820, "height" => 523),
          BX_RESIZE_IMAGE_PROPORTIONAL,
          true, $arFilter
        );

        ?>
        <img src="<?=$arFileTmp["src"]?>">
      <?endforeach;?>
    <?}endif;?>

A
Alexey Emelyanov, 2017-09-08
@babarun

Show the contents of the variables:

  • $EX
  • $arFile

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question