Answer the question
In order to leave comments, you need to log in
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
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"); // Получаем значение
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"];
...
'NEW_PARAM'=>$peremen,
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question