remove bootstrap , unset JS Topic is solved

Be informed that this forum is not an official support forum for Joomla! 4.0. Any issues regarding Joomla! 4.0 must be reported at https://issues.joomla.org/.

Joomla 4.0 is still in Beta stage. This forum should be used for sharing information about Joomla! 4.0.
Post Reply
erick-b
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 139
Joined: Tue Feb 17, 2015 10:25 am

remove bootstrap , unset JS

Post by erick-b » Tue Feb 11, 2020 8:54 am

1) Do you know how it is possible to remove totally bootstrap from J4 (beta 1) ?

<script src="/media/vendor/bootstrap/js/bootstrap.bundle.min.js?4.4.1"></script>

I am trying
unset($scripts[ '/media/vendor/bootstrap/js/bootstrap.bundle.min.js']);
or/and
JHtml::_('bootstrap.framework',false);

but it does not work



thanks for helping

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 22963
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: remove bootstrap , unset JS

Post by pe7er » Wed Feb 12, 2020 8:35 am

To remove all JavaScript, you could try:

Code: Select all

use Joomla\CMS\Factory;

$doc = Factory::getDocument();
$doc->_script = [];
$doc->_scripts = [];
Kind Regards,
Peter Martin, Global Moderator
https://db8.nl - Joomla specialist, Nijmegen, Nederland
The best website: https://the-best-website.com

User avatar
AMurray
Joomla! Champion
Joomla! Champion
Posts: 6466
Joined: Sat Feb 13, 2010 7:35 am
Location: Australia

Re: remove bootstrap , unset JS

Post by AMurray » Wed Feb 12, 2020 8:42 am

J4 templates are built on Bootstrap 4....without it, they won't won't work.....?
Regards,
--------------------------------------------------------------
A Murray
Help you I can, yes!. Post your question, you should. Keep it on topic you must!
Use the Forc....Forum Post Assistant my young Padawan!

erick-b
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 139
Joined: Tue Feb 17, 2015 10:25 am

Re: remove bootstrap , unset JS

Post by erick-b » Wed Feb 12, 2020 8:51 am

not true
I am running a website with j4 and my own template without bootstrap, or bootcrap if you prefer

you can use :
<jdoc:include type="head" />

but instead you can do :
<jdoc:include type="metas" />
<jdoc:include type="styles" />
<jdoc:include type="scripts" />

if you remove scripts you can load your own js

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 22963
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: remove bootstrap , unset JS

Post by pe7er » Wed Feb 12, 2020 1:28 pm

erick-b wrote:
Wed Feb 12, 2020 8:51 am
if you remove scripts you can load your own js
Have you tried the small script that I gave you?
Kind Regards,
Peter Martin, Global Moderator
https://db8.nl - Joomla specialist, Nijmegen, Nederland
The best website: https://the-best-website.com

erick-b
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 139
Joined: Tue Feb 17, 2015 10:25 am

Re: remove bootstrap , unset JS

Post by erick-b » Wed Feb 12, 2020 2:41 pm

Sorry but

$doc->_script = [];
$doc->_scripts = [];

is not working

the best method seems
<jdoc:include type="metas" />
<jdoc:include type="styles" />
instead of
<jdoc:include type="head" />


for Joomla 4.x only

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 22963
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: remove bootstrap , unset JS

Post by pe7er » Wed Feb 12, 2020 2:49 pm

My small script works in J3.x. I did not know if it would work in J4 as well...
Thanks!
Kind Regards,
Peter Martin, Global Moderator
https://db8.nl - Joomla specialist, Nijmegen, Nederland
The best website: https://the-best-website.com

erick-b
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 139
Joined: Tue Feb 17, 2015 10:25 am

Re: remove bootstrap , unset JS

Post by erick-b » Wed Feb 12, 2020 2:51 pm

in J3 I have no problem to unset scripts

deleted user

Re: remove bootstrap , unset JS

Post by deleted user » Wed Feb 12, 2020 4:48 pm

The problem is the half-hearted web asset API in 4.0. A lot of core media doesn't exist in the Document object when the template file is actually executed as a PHP script, rather it gets added later on in the process and the only reliable way to get to it is going to be with a hook for the onBeforeCompileHead event. So you're going to need something like this in your file (which, hopefully will actually work as intended):

Code: Select all

\Joomla\CMS\Factory::getApplication()->getDispatcher()->addListener(
    'onBeforeCompileHead',
    function () {
        $doc = \Joomla\CMS\Factory::getDocument();
        
        // do whatever unset stuff you need to do here
    }
);

erick-b
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 139
Joined: Tue Feb 17, 2015 10:25 am

Re: remove bootstrap , unset JS

Post by erick-b » Wed Feb 12, 2020 4:51 pm

perfect !

thanks a lot

MarcusR
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Fri Jan 08, 2021 4:07 pm

Re: remove bootstrap , unset JS

Post by MarcusR » Fri Jan 08, 2021 4:14 pm

Hey erick-b,

it seems, that you manage it,so could you share your solution?
My solution doesn´t work for joomla 4.
here is my simplify script

Code: Select all

public function onBeforeCompileHead()
{
$doc = JFactory::getDocument();
unset($doc->scripts[JURI::root(true).'/media/vendor/bootstrap/js/bootstrap.bundle.min.js']);
unset($doc->scripts[JURI::root(true).'/media/vendor/bootstrap/js/bootstrap.min.js']);
unset($doc->scripts[JURI::root(true).'/vendor/bootstrap/bootstrap.min.js']);
unset($doc->scripts[JURI::root(true).'/vendor/bootstrap/bootstrap.bundle.min.js']);
unset($doc->script['bootstrap.js.bundle']);
unset($doc->script['bootstrap.js']);
}
Thank you very much for helping me.

Marcus


Post Reply

Return to “Joomla! 4 Related”