I want to remove individual css files, code not working!

For Joomla! 4.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Post Reply
tutonn
Joomla! Apprentice
Joomla! Apprentice
Posts: 28
Joined: Wed Apr 23, 2014 11:53 am
Contact:

I want to remove individual css files, code not working!

Post by tutonn » Fri May 03, 2024 11:56 am

Hi everyone!
Please help me correct the codes below. after using this code, I got an error message with an error page

"0 Undefined method unregisterasset in class Joomla\CMS\WebAsset\WebAssetManager"

$wa = $this->getWebAssetManager();

// Remove individual CSS files
$wa->unregisterAsset('main.css');
$wa->unregisterAsset('jquery.bootstrap-touchspin.css');
$wa->unregisterAsset('jquery-ui.slider.min.css');
$wa->unregisterAsset('colors_standard.min.css');
$wa->unregisterAsset('template.min.css');
$wa->unregisterAsset('joomla-alert.min.css');

Please correct me.

Thanks in advance. it is also urgent for me too.

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2962
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: I want to remove individual css files, code not working!

Post by SharkyKZ » Fri May 03, 2024 12:01 pm

See answer on JSE https://joomla.stackexchange.com/a/33728. Though randomly disabling assets will cause parts of your site to break.

tutonn
Joomla! Apprentice
Joomla! Apprentice
Posts: 28
Joined: Wed Apr 23, 2014 11:53 am
Contact:

Re: I want to remove individual css files, code not working!

Post by tutonn » Fri May 03, 2024 12:18 pm

Thanks for your quick reply. But this url does not help me. I appreciate your help, thanks again.

User avatar
carlitorweb
Joomla! Intern
Joomla! Intern
Posts: 68
Joined: Tue May 08, 2018 9:03 pm

Re: I want to remove individual css files, code not working!

Post by carlitorweb » Fri May 03, 2024 3:51 pm

tutonn wrote:
Fri May 03, 2024 12:18 pm
Thanks for your quick reply. But this url does not help me. I appreciate your help, thanks again.
You should read again, because in that link is where you will find the answer. The method unregisterAsset is not part of the class WebAssetManager. You need use instead disableAsset
The future will be automated, decentralized, and digital.

tutonn
Joomla! Apprentice
Joomla! Apprentice
Posts: 28
Joined: Wed Apr 23, 2014 11:53 am
Contact:

Re: I want to remove individual css files, code not working!

Post by tutonn » Wed May 08, 2024 3:30 pm

Thanks, Carlitorweb, for your kind reply. I will try this. Sorry to reply so late.

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2962
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: I want to remove individual css files, code not working!

Post by SharkyKZ » Thu May 09, 2024 5:56 am

disableAsset() may not work correctly, as mentioned in the answer. You also need to use correct asset names, not file names. You can see asset names by enabling debug and then inspecting data-asset-name attribute in <link> and <script> tags.

tutonn
Joomla! Apprentice
Joomla! Apprentice
Posts: 28
Joined: Wed Apr 23, 2014 11:53 am
Contact:

Re: I want to remove individual css files, code not working!

Post by tutonn » Sun May 12, 2024 7:51 pm

Dear SharkyKZ, Thanks a lot for your kind reply.


Post Reply

Return to “Joomla! 4.x Coding”