A
A
Alexander2021-01-11 17:10:24
1C-Bitrix
Alexander, 2021-01-11 17:10:24

How to filter the list of news by dates Activity start and Activity end?

It is necessary to set filtering for the list of news that is displayed through the news.list component
by the start date of activity (DATE_ACTIVE_FROM) and date end of activity (DATE_ACTIVE_TO)

I know that the easiest way to filter the list is using arrFilter
Now I filter this way:

$from = date('10.01.2021'); 
$to = date("16.01.2021"); 
$arrFilter = Array(
  ">=DATE_ACTIVE_FROM" => $from, 
  "<=DATE_ACTIVE_TO" => $to
);

and then I specify the name of the variable with the filter in the call code
APPLICATION->IncludeComponent(
  "bitrix:news.list",
  "slider_main",
  Array(
 "FILTER_NAME" => "arrFilterDate",
…
)
);


The filtering works fine, but I don't like that the variables are not set through the component's setup window.

Is it possible to somehow filter the list of news in news.list by setting additional parameters in the component template, so that the activity start date (DATE_ACTIVE_FROM) and the activity end date can be set in the component editing mode in the Additional settings block, so that the component can process the specified parameters the same as in the arrFilter variable, or pass the resulting parameters to the arrFilter variable already in the component template, for example, in the result_modifier.php file?

5ffc5c1d3f22c912953960.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Emelyanov, 2021-01-11
@babarun

Copy the component template and add .parameters.php to it with the settings you need. But in this case, they will not be taken into account in the news selection, because GetList knows nothing about them.
You can read more here https://ydmitry.ru/blog/4-sposoba-rasshirit-standa...
Alternatively, you can place an additional "configuration" component in front of the component, the settings of which will fall into the global arrFilter for your component, but this is too frozen for your case.
It's easier to customize a standard component for your task.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question