добавление дополнительных файлов в шаблон сайта
вариант 1 без условий в init.php
Bitrix\Main\Page\Asset::getInstance()->addCss("/local/assets/css/sds.css?2");
Bitrix\Main\Page\Asset::getInstance()->addJs("/bitrix/js/main/jquery/jquery-3.6.0.min.js");
Bitrix\Main\Page\Asset::getInstance()->addJs("/local/assets/js/sds.js"); |
вариант 2. в обработчике в init.php
use \Bitrix\Main\EventManager;
use Bitrix\Main\Page\Asset;
$eventManager = EventManager::getInstance();
$eventManager->addEventHandler('main', 'OnProlog', function(){
$request = \Bitrix\Main\Application::getInstance()->getContext()->getRequest();
$curUri = parse_url($request->getRequestUri());
$curUri = $curUri['path'];
if(strpos($curUri, '/page/hr_otdel/')!==false){
Asset::getInstance()->addJs('/local/files/hr/script_hr.js?11', true);
}
elseif(strpos($curUri, '/knowledge/baza_znaniy_v_svetloy_teme4/') !==false && $_GET['test'] == 'okr'){
Asset::getInstance()->addJs('/local/files/base/s1.js?11', true);
}
elseif(strpos($curUri, '/page/zakaz_produktsii/agrotekhnoligii_zayavki/') !==false ){
Asset::getInstance()->addJs('/local/files/script2.js?11', true);
}
Asset::getInstance()->addJs('/local/files/all/test.js?337', true);
Asset::getInstance()->addCss( '/local/files/all/style.css?337', true);
}); |