1

Tell me please. How to load jQuery in Joomla 4 if it has not been loaded yet?

1
  • Your question is clear, but has been flagged by the system as being low-quality due to its length. Might you edit your question to include attempts that you've made and relevant online resources that are on-topic? I like to upvote questions, but my personal criteria requires that effort/research is demonstrated in the question.
    – mickmackusa
    Jan 13 at 19:53
6

You should be able to load it like so:

Joomla\CMS\HTML\HTMLHelper::_('jquery.framework');

Else, if you're using Joomla's Web Asset Manager, then you can define it as a dependency in your JSON object:

{
  "name": "foobar",
  "type": "script",
  "uri": "com_mycomponent/script.min.js",
  "dependencies": [
    "jquery"
  ]
},
0

Lodder answer is certainly useful, but not what I wanted to see. The correct loading of the embedded jquery looks like this.

use Joomla\CMS\Factory;

$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$wa->useScript('jquery');

This will work if jquery has not been loaded before.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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