D
D
Dmitry Mityaev2018-03-21 19:34:32
1C-Bitrix
Dmitry Mityaev, 2018-03-21 19:34:32

BITRIX: how to display a property correctly?

Hello.
People, tell me, please,
In the infoblock I created the "File" property, multiple. Uploaded .pdf files to it.
I need to display the file name from an array.
If there is one element, then it turns out to be done like this:

<?=$arResult["DISPLAY_PROPERTIES"]["FILE"]["FILE_VALUE"]["ORIGINAL_NAME"];?>

But if there is an array of elements (when there are several files), you need to display this through foreach.
I wrote the code, but nothing works (((
Please correct me, I still haven’t really learned how to work with multidimensional arrays ...
<?if(is_array($arResult["DISPLAY_PROPERTIES"]["FILE"]["FILE_VALUE"]["ORIGINAL_NAME"])):?>  <?foreach($arResult["DISPLAY_PROPERTIES"]["FILE"]["FILE_VALUE"] as $pid=>$arProperty):?>
        <?$arProperty["ORIGINAL_NAME"]?>
  <?endforeach;?>
    <?else:?>
    
  <?=$arResult["DISPLAY_PROPERTIES"]["FILE"]["FILE_VALUE"]["ORIGINAL_NAME"];?>
    
<?endif?>

A colleague told me that you first need to check whether the element is an array, if so, we display it as an array.
If not, we simply output:
<?=$arResult["DISPLAY_PROPERTIES"]["FILE"]["FILE_VALUE"]["ORIGINAL_NAME"];?>

Help me please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Epifanov, 2018-03-21
@DMityaev

you are checking for is_array like this

$arResult["DISPLAY_PROPERTIES"]["FILE"]["FILE_VALUE"]["ORIGINAL_NAME"]

and iterate over
$arResult["DISPLAY_PROPERTIES"]["FILE"]["FILE_VALUE"]

nothing bothers you?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question