A
A
AndreyBAN2021-11-22 12:17:47
PHP
AndreyBAN, 2021-11-22 12:17:47

How to check if the script is connected in the Bitrix component template?

Greetings.
C ran into the following situation.
I created a component, scripts are connected in it that are in /local/components/name-component/js/name.js (not the essence)
In the component template it is connected using $this->addExternalJs
The problem is the following.
If the component needs to be used several times on the same page, then the scripts specified via $this->addExternalJs are
re-included. Is it possible, except for passing a parameter to a component, to connect with a check, if the script is connected, then we don’t connect it anymore?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Ekaterina, 2021-12-02
@AndreyBAN

In these cases, CJSCore::RegisterExt should be used . In addition to checking for "already connected", it can also pull up dependencies. Useful when your script needs an external library (jquery, etc.) or has a dependency on native libraries. As a bonus, he also knows how to pull up styles.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question