1

I built a custom Joomla 4 template and unfortunately Joomla is automatically loading collapse.min.js

When I view the page source I see this in the head:

<script src="/media/vendor/bootstrap/js/collapse.min.js?5.1.3" type="module"></script>

This is conflicting with the curated Boostrap 5 files that my template already loads. The result that anything in my template that uses Bootstrap collapse (accordion, navbar) is broken.

Interestingly, this does not happen on my local (WAMP) environment. How do I prevent Joomla from loading collapse.min.js in my template?

1
  • Why don't you want to use the included scripts? Using them should provide frontend performance benefit as they're split by Bootstrap component and are loaded only when needed.
    – Sharky
    Commented Apr 5, 2022 at 6:05

1 Answer 1

0

If you want to load a single file instead of separate Bootstrap components, you can declare the asset in your template's joomla.asset.json file. Note you will need to do this for all Bootstrap components.

{
  "name": "bootstrap.collapse",
  "type": "script",
  "uri": "your-bootstrap-file.min.js",
  "attributes": {
    "type": "module"
  },
  "version": "5.1.3"
}

If you're loading split files like the core ones, you can create overrides by placing your files in the appropriate directory. In this case that would be:

templates/[your_template]/js/vendor/bootstrap/collapse.min.js

Or, if you're creating an "inheritable" template (feature introduced in Joomla 4.1):

media/templates/site/[your_template]/js/vendor/bootstrap/collapse.min.js
1
  • I'm still in the mindset of J3x, which is where I started building custom templates. So the template does not use a .json file, which is probably the issue (although, I have another live site that uses this template, where this issue does not occur). This is my problem with developing Joomla 4 templates: Because I am a relative novice, and because official J4 template documentation is incomplete, my template development has been trial & error. I will have to hunt down more info on joomla.asset.json Thanks!
    – Bold
    Commented Apr 14, 2022 at 14:15

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.