Answer the question
In order to leave comments, you need to log in
How to remove duplicates when displaying the properties of elements on the Bitrix website?
I made a table on the site, and added filtering by the necessary properties. But there are duplicates. Screen under the spoiler The
question is what needs to be added to remove duplicates, I can’t figure something out. Can anyone tell
me the code used:
<select class="drop" id="regionDropdown">
<option value="All">Показать все</option>
<?foreach($arResult["ITEMS"] as $arItem):?>
<?if(!empty($arItem['DISPLAY_PROPERTIES']['FILM_TYPES']['VALUE'])):?>
<option value="<?=$arItem['DISPLAY_PROPERTIES']['FILM_TYPES']['DISPLAY_VALUE'];?>"><? endif; ?><?=$arItem['DISPLAY_PROPERTIES']['FILM_TYPES']['DISPLAY_VALUE'];?></option>
<? endif; ?>
<? endforeach; ?>
</select>
Answer the question
In order to leave comments, you need to log in
In result_modifier.php
if($arResult['ITEMS']) {
$arResult['FILE_TYPES'] = $filmTypes = [];
foreach($arResult['ITEMS'] as $key => $arItem) {
$filmTypesProp = isset($arItem['DISPLAY_PROPERTIES']['FILM_TYPES']) ? $arItem['DISPLAY_PROPERTIES']['FILM_TYPES'] : false;
$value = $filmTypesProp && $filmTypesProp['VALUE'] ? $filmTypesProp['VALUE'] : false;
$displayValue = $filmTypesProp && $filmTypesProp['DISPLAY_VALUE'] ? $filmTypesProp['DISPLAY_VALUE'] : false;
if($value && $displayValue) {
$filmTypes['VALUE'][] = $value;
$filmTypes['DISPLAY_VALUE'][] = $displayValue;
}
}
$arResult['FILE_TYPES'] = [
'VALUE' => array_values(array_unique($filmTypes['VALUE'])),
'DISPLAY_VALUE' => array_values(array_unique($filmTypes['DISPLAY_VALUE'])),
];
}
<?if(isset($arResult['FILE_TYPES']) && $arResult['FILE_TYPES']):?>
<select class="drop" id="regionDropdown">
<option value="All">Показать все</option>
<?foreach($arResult['FILE_TYPES']['DISPLAY_VALUE'] as $value):?>
<option value="<?=$value;?>"><?=$value;?></option>
<?endforeach;?>
</select>
<?endif;?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question