Documentation

Asset

Asset class is responsible for connecting styles and scripts. It implements Singleton pattern. Query the object via Bitrix\Main\Page\Asset::getInstance.

Used instead the methods of the old core: CMain::AddHeadScript, CMain::SetAdditionalCss, CMain::AddHeadString.

Queries to the namespace:

Method Description Available from version
addString Adds string to <head>…</head>.
addCss Adds css to the <head>…</head> site section.
addJs Adds js to the <head>…</head> site section.

Example

// D7
use Bitrix\Main\Page\Asset;

Asset::getInstance()->addJs(SITE_TEMPLATE_PATH . "/js/fix.js");
Asset::getInstance()->addCss(SITE_TEMPLATE_PATH . "/styles/fix.css");
Asset::getInstance()->addString("<link href='http://fonts.googleapis.com/css?family=PT+Sans:400&subset=cyrillic' rel='stylesheet' type='text/css'>"); 


© «Bitrix24», 2001-2022
Up