D
D
Dmitry Grabko2017-04-18 10:24:34
1C-Bitrix
Dmitry Grabko, 2017-04-18 10:24:34

How to split news preview by condition in Bitrix?

The page displays active and past promotions.
fe1921bce6e044ac869717801a6a44d4.png
Question: how to separate the news for which the "end of promotion" field is set to a new line with a separate title. The question is in specifying the condition in the template ?
Template code:

<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();
/** @var array $arParams */
/** @var array $arResult */
/** @global CMain $APPLICATION */
/** @global CUser $USER */
/** @global CDatabase $DB */
/** @var CBitrixComponentTemplate $this */
/** @var string $templateName */
/** @var string $templateFile */
/** @var string $templateFolder */
/** @var string $componentPath */
/** @var CBitrixComponent $component */
$this->setFrameMode(true);
?>
<h1><?$APPLICATION->ShowTitle()?></h1>
<div class="news-page">	
<?foreach($arResult["ITEMS"] as $arItem):?>
  <?
  // echo($arItem['PROPERTIES']['SALE_END']['VALUE']);
  // echo "<br>";
  // echo date('d.m.Y h:i:s');
  $sale_class = '';
  $sale_end = $arItem['PROPERTIES']['SALE_END']['VALUE'];
    if(strtotime($sale_end) < strtotime(date('d.m.Y h:i:s')) && !empty($sale_end)) {
      $sale_class = "sale-grey";
    }
  $this->AddEditAction($arItem['ID'], $arItem['EDIT_LINK'], CIBlock::GetArrayByID($arItem["IBLOCK_ID"], "ELEMENT_EDIT"));
  $this->AddDeleteAction($arItem['ID'], $arItem['DELETE_LINK'], CIBlock::GetArrayByID($arItem["IBLOCK_ID"], "ELEMENT_DELETE"), array("CONFIRM" => GetMessage('CT_BNL_ELEMENT_DELETE_CONFIRM')));
  ?>
  <div class="news" id="<?=$this->GetEditAreaId($arItem['ID']);?>">

    <span class="date"><?echo $arItem["DISPLAY_ACTIVE_FROM"]?></span>

    <a class="title" href="<?=$arItem["DETAIL_PAGE_URL"]?>"><?echo $arItem["NAME"]?></a>
    <div class="<?=$sale_class?>">
    <?if($arItem["PREVIEW_PICTURE"]["SRC"]!=""):?>
      <a href="<?=$arItem["DETAIL_PAGE_URL"]?>" ><img alt="<?echo $arItem["NAME"]?>" title="<?echo $arItem["NAME"]?>" src="<?=$arItem["PREVIEW_PICTURE"]["SRC"]?>"></a>
    <?endif;?>
    </div>
    <?echo $arItem["PREVIEW_TEXT"];?>
    <a class="about" href="<?=$arItem["DETAIL_PAGE_URL"]?>">Подробнее</a>
    <?if ($sale_end){?>
    <?
      $date_end = explode(' ', $sale_end);  
    ?>
    <div class="sale-end">
      Дата окончания акции:<br>
      <span><?=$date_end[0]?></span>
    </div>
    <?}?>

  </div>
          
<?endforeach;?>
</div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Goncharov, 2017-04-18
@Dima_So

Run two loops with different conditions

<?foreach($arResult["ITEMS"] as $arItem):?>
    <? if (empty($arItem['PROPERTIES']['SALE_END']['VALUE'])) :?>
        Выводим без акции
    <? endif;?>
<?endforeach;?>

<?foreach($arResult["ITEMS"] as $arItem):?>
    <? if (!empty($arItem['PROPERTIES']['SALE_END']['VALUE'])) :?>
        Выводим с акцией
    <? endif;?>
<?endforeach;?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question