J
J
jaakirqweo212021-05-13 16:49:19
1C-Bitrix
jaakirqweo21, 2021-05-13 16:49:19

Bitrix how to display the file property?

There are two components that display sections and their elements.
I need to make the element output the FILE property from the admin panel, how to do it?
Components:

<?php
//разделы
$resSect = CIBlockSection::GetList(
    [],
    [
        'IBLOCK_ID' => 37,
        'CODE' => $arSectCodes
    ],
    false,
    [
        'ID',
        'NAME',
        'CODE',
        'UF_ICON',
    ]
);
while($ob = $resSect->GetNextElement())
{
    $arSection = $ob -> GetFields();
}

//элементы
$arSelect = Array("ID", "NAME", "CODE", "DATE_ACTIVE_FROM", "PROPERTY_*");
$arFilter = Array("IBLOCK_ID"=>37, "ACTIVE"=>"Y");
$res = CIBlockElement::GetList(Array(), $arFilter, false, false, $arSelect);
while($ob = $res->GetNextElement())
{
    $arElements[] = $ob->GetFields();
}

foreach ($arElements as $key => $arItem) {
    $rsSections = CIBlockElement::GetElementGroups($arItem['ID']);
    while ($arSection = $rsSections->Fetch())
    {

        $arSectionList= array(
            'ID' => $arSection['ID'],
            'NAME' => $arSection['NAME'],
            'CODE' => $arSection['CODE'],
        );

        $arItem= array(
            'ID' => $arItem['ID'],
            'NAME' => $arItem['NAME'],
            'CODE' => $arItem['CODE'],
            'DATE_ACTIVE_FROM' => $arItem['DATE_ACTIVE_FROM'],
            'FILE' => $arItem['FILE']['VALUE'],
        );

        $arResult['ITEMS_BY_GROUP'][$arSectionList["ID"]][] = $arItem;
    }

}
?>

The conclusion itself:
<? foreach ($arResult['SECTIONS'] as $key => $sect) { ?>

            <div class="doc">
                <div class="wrapper-title__docs">
                    <div class="title__docs">
                        <?=$sect["NAME"]?>
                    </div>
                       <button class="wp__category--btn"><span></span><span></span></button>
                </div>

                <?if($arResult['ITEMS_BY_GROUP'][$sect["ID"]]){?>
                    <div class="document-wrapper__inner">

                        <? foreach ($arResult['ITEMS_BY_GROUP'][$sect["ID"]] as $item) { ?>

                            <div class="document__item">
                                    <span class="document__date">
                    <a href="<?=$item["FILE"]["VALUE"]?>" target="_blank">
                        <?=$item['DATE_ACTIVE_FROM']?>
                    </a>
                </span>
                                <span class="document__name">
                <a href="<?=$item["FILE"]["VALUE"]?>" target="_blank"><?=$item["NAME"]?></a>
            </span>
                                <div class="document__file">
                                    <a href="<?=$item["FILE"]["VALUE"]?>" style="display: flex;" target="_blank">
                                        <span class="document__file-type">PDF</span>
                                        <span class="document__file-icon">
                        <svg width="26" height="29" viewBox="0 0 26 29" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M14.9824 22.4628L21.878 9.46256L23.5 10.1672L16.0692 23.9997L10.0482 23.9997L2.49997 10.1672L4.08598 9.46256L11.1937 22.4628L14.9824 22.4628Z" fill="#002F6C"></path>
<path d="M13.9624 20.8391L12.0549 20.8391L12.0549 -0.000292513L13.9624 -0.000292679L13.9624 20.8391Z" fill="#002F6C"></path>
<path d="M26.0001 29L0.00012207 29L-1.54337e-05 26.9998L26 26.9998L26.0001 29Z" fill="#002F6C"></path>
</svg>
                    </span>
                                    </a>
                                </div>
                            </div>
                        <? } ?>

                    </div>
                <?}?>

            </div>

            <? } ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zhyeba, 2021-05-14
@zhyeba

If you understand the question correctly, <?=$item["FILE"]["VALUE"]?> will display the ID of this file for you (this is how it is stored in the database). Then, through https://dev.1c-bitrix.ru/api_help/main/reference/c... you get a link to this file and put it in the href of the tag a

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question