V
V
Vladimir2017-01-12 15:57:53
PHP
Vladimir, 2017-01-12 15:57:53

How to program a slider on Bitrix?

Good afternoon!
I need to make a small slider.
Using Catalog.section
Here is a snippet from the result modifire for the slider.

foreach ($arResult["PROPERTY_IMAGES_VALUE"] as $arImages) 
{
$arResult["IMAGES"][] = CFile::GetFileArray($arImages);
}

IMAGES - one of the infoblock properties for added images
Here is a template
<?foreach ($arResult["ITEMS"] as $arItem) {?>
<div class = "slider" id = "slider_images-<?=$arItem["ID"]?>">
    <div class = "slider">
        <?foreach ($arItem["IMAGES"] as $arPhoto) {
            ?><div><img src="<?=$arPhoto["SRC"]?>"></div><?
        }?>
    </div>
    <div class = "s-navigation">
        <?foreach ($arItem["IMAGES"] as $arPhoto) {
            ?><div><img src="<?=$arPhoto["SRC"]?>"></div><?
        }?>
    </div>
</div>
    <?
    }?>

But in the end it doesn't work for me. Empty. I use code
var_dump($arResult["IMAGES"])
in result modifire It gives me Null.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Korolev, 2017-01-12
Bolotov @VladimirBolotov

You use catalog.section, which, firstly, has a selection of elements in $arResult["ITEMS"], and secondly, PROPERTY_IMAGES_VALUE is used if you yourself will select properties via CIBlockElement::GetList (but since images are stored in a multiple property, then this is usually solved not through CIBlockElement::GetList, but through CIBlockProperty::GetList).
Since you are processing a ready-made selection of elements in result_modifier.php, then access to the values ​​of the properties of the elements goes not through PROPERTY_IMAGES_VALUE, but like this: ["PROPERTIES"]["IMAGES"]["VALUE"].
Those. In the general case, for your option, you need such a construction:

foreach ($arResult["ITEMS"] as &$arItem) 
{
  $arItem["IMAGES"] = array();
  foreach ($arItem["PROPERTIES"]["IMAGES"]["VALUE"] as $imageId) 
  {
    $arItem["IMAGES"][] = CFile::GetFileArray($imageId);
  }
}
unset($arItem);

and in situations like this, it's more convenient to look at the entire result to see what data is where:
var_dump($arResult);
or
print_r($arResult);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question