K
K
krispey1022021-06-17 10:46:13
1C-Bitrix
krispey102, 2021-06-17 10:46:13

Bitrix how to transfer a variable from one template to another and use it?

a component with elements is called in the page template, I need to filter this component by values ​​taken from result_modifier.php. The result_modifier.php itself is the component file that is called on the page. How to pass a variable from result_modifier to the general page where this component is called? I tried it through a global variable, but the main page does not see it, I also tried it through a deferred function, it is called on the main page, but I cannot use this variable. How else can you pass a variable from one template to another?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
BornTo FreeFall, 2021-06-17
@BornToFreeFall

There are two ways out:
1. Global variable $GLOBALS['SOME_VARIABLE_NAME'] = $SOME_VARIABLE_VALUE
2. Wrapper class (I say right away, I saw the example, I had to make a similar implementation):

Class GarbageStorage{
  private static $globalStorage = [];
  public static function set ($storageName,  $variableValue){ self::$globalStorage[$storageName] = $variableValue;}
  public static function get ($storageName){ return self::$globalStorage[$storageName];}
}
соответственно использование
\GarbageStorage::set("SomeIdentificator",  $arResult["ID"]);                      // Устанавливаем значение
\GarbageStorage::get("SomeIdentificator");                                               // Получаем значение

T
tgarl, 2021-06-18
@tgarl

result_modifier.php - here, of course, you can get your data, but you need to put it in the component's cache, if it's not already there, to pass it to
component_epilog.php result_modifier.
and everything is simple

$GLOBALS['peremen'] = $arResult["AR_LIST_SERVICES_FILTER"];

now below outside of the component below you have $peremen which you pass to the component as a parameter
...
'NEW_PARAM'=>$peremen,
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question