I know I can use many of the items found in this documentation such as jQuery


by doing something simple like this JHtml::_('jquery.framework', false);

However, say I want to use React, I know I can include it using addScript but what if I wanted to use it for multiple modules/plugins/components. Is there a way to make it globally available like jQuery is?


1 Answer 1


Yes. This will be short -- you need to understand the code you're working with because this technique is one of the most powerful ones Joomla affords you and there is basically no documentation of it apart from the code itself, so do it only after tracking through the code and understanding the ramifications.

HTMLHelper has a register method you can call to register a routine of your own with it.

JHtml::register('react', MyClass::loadReact)

Once this gets executed, any call to JHtml::_('react') will execute the loadReact method in the class MyClass. The basic idea is it keeps a list of keys that point to methods it needs to call, none of which are required to be members of itself. Then, when told to call that key, it looks it up and executes it. It's the same mechanism used to load bootstrap and jquery today.

  • And as I would not know if extension a, b or c is installed or any combination, I assume registering twice does not cause a problem and only registers once? Or is it better to check first prior to registering?
    – Eoin
    Commented Jun 20, 2019 at 19:29
  • 1
    Last registration wins; every registration for a term overwrites the previous one. Which means for your case you'll probably want to create your own name for it (just in case someone registers without looking first) and yes, you can check with JHtml::isRegistered('my.framework') before registering if you want to be really clean about it.
    – Arlen
    Commented Jun 21, 2019 at 21:17
  • 1
    I just noticed, my example uses 'react' but in the explanation I use 'my.framework'. Sigh.
    – Arlen
    Commented Jul 16, 2019 at 13:26
  • Thanks for coming back to correct
    – Eoin
    Commented Jul 16, 2019 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.