E
E
Eugene M2018-11-07 09:09:57
1C-Bitrix
Eugene M, 2018-11-07 09:09:57

How to display PREVIEW_PICTURE in horizontal_multilevel template.php?

In the template like this:

<?if ($arItem["DEPTH_LEVEL"] == 1):?>
   
   <li class="<?if ($arItem["SELECTED"]):?>active<?endif?>"><a href="<?=$arItem["LINK"]?>"><?=$arItem["TEXT"]?></a></li>
<?else:?>
      <li<?if ($arItem["SELECTED"]):?> class="item-selected"<?endif?>>
                <a href="<?=$arItem["LINK"]?>"><?=$arItem["TEXT"]?></a>
      <img src="<?=$arItem["PREVIEW_PICTURE"]["SRC"]?>" /></li>
<?endif?>

and added result_modifier.php
<?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();
foreach($arResult["ITEMS"] as $i=>$arItem) {
   if (is_array($arItem["PREVIEW_PICTURE"])) {
                $ratio = $arItem["PREVIEW_PICTURE"]["WIDTH"] / $arItem["PREVIEW_PICTURE"]["HEIGHT"];
      $width = 250;
      $height = round($width / $ratio);
      $img = CFile::ResizeImageGet($arItem["PREVIEW_PICTURE"], array("width" => $width, "height" => $height), BX_RESIZE_IMAGE_EXACT);
      $arResult["ITEMS"][$i]["PREVIEW_PICTURE"]["SRC"] = $img["src"];
      $arResult["ITEMS"][$i]["PREVIEW_PICTURE"]["WIDTH"] = $width;
      $arResult["ITEMS"][$i]["PREVIEW_PICTURE"]["HEIGHT"] = $height;
   }
}
?>

and for some reason it does not work, tell me where the error is?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Ainur Valiev, 2018-11-07
@vaajnur

CFile::ResizeImageGet($arItem["PREVIEW_PICTURE"]['ID'] ,
1st parameter id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question