Skip to main content

unset($doc->_scripts[JUri::base(true)'/path/to/file.js'])

unset($doc->_scripts[JUri::base(true)'/path/to/file.js'])

is mostly how to do it, some scripts might add the full urlURL and some might not.

For script declaration it combines most scripts into one rather then seperatethan separate them, also the template is not the last place to execute before the page is rendered, so more could still be added to the script array. I am not 100% on this but I believe modules are rendered after the template and then inserted, components load based on the menu item so they load before. Also plugins can add more scripts afterwords.

In Summarysummary, depending on where it is added, it may not be possible in the template,template; plugins could be the only way.

UPDATE: Like I said, it cannot be done with just templates, but I found a way to get around that with a simple system plugin that can be used to allow it on any site. This is something that would be useful in the core and I might try to do a pull request to get it added, though anyone is welcome to. However its unlikely to be added "next release"

This is sort of inspired by wordpressWordPress but I was blown away when, by looking at source code I discovered it was basically completely supported in core, just the final step of defining a file in the template was missed. Such a useful functionality!

Note: I did this from memory, so it might not be 100% correct, looking into the JDispatcherJDispatcher class might be a good idea if it does not work. This

This can be very useful in many projects that need some simple plugin functionality specifically for that site, but making a custom plugin is way more work then it needs to be.

unset($doc->_scripts[JUri::base(true)'/path/to/file.js'])

is mostly how to do it, some scripts might add the full url and some might not.

For script declaration it combines most scripts into one rather then seperate them, also the template is not the last place to execute before the page is rendered, so more could still be added to the script array. I am not 100% on this but I believe modules are rendered after the template and then inserted, components load based on the menu item so they load before. Also plugins can add more scripts afterwords.

In Summary, depending on where it is added it may not be possible in the template, plugins could be the only way.

UPDATE Like I said it cannot be done with just templates, but I found a way to get around that with a simple system plugin that can be used to allow it on any site. This is something that would be useful in the core and I might try to do a pull request to get it added, though anyone is welcome to. However its unlikely to be added "next release"

This is sort of inspired by wordpress but I was blown away when, by looking at source code I discovered it was basically completely supported in core, just the final step of defining a file in the template was missed. Such a useful functionality!

Note: I did this from memory, so it might not be 100% correct, looking into the JDispatcher class might be a good idea if it does not work. This can be very useful in many projects that need some simple plugin functionality specifically for that site, but making a custom plugin is way more work then it needs to be.

unset($doc->_scripts[JUri::base(true)'/path/to/file.js'])

is mostly how to do it, some scripts might add the full URL and some might not.

For script declaration it combines most scripts into one rather than separate them, also the template is not the last place to execute before the page is rendered, so more could still be added to the script array. I am not 100% on this but I believe modules are rendered after the template and then inserted, components load based on the menu item so they load before. Also plugins can add more scripts afterwords.

In summary, depending on where it is added, it may not be possible in the template; plugins could be the only way.

UPDATE: Like I said, it cannot be done with just templates, but I found a way to get around that with a simple system plugin that can be used to allow it on any site. This is something that would be useful in the core and I might try to do a pull request to get it added, though anyone is welcome to. However its unlikely to be added "next release"

This is sort of inspired by WordPress but I was blown away when, by looking at source code I discovered it was basically completely supported in core, just the final step of defining a file in the template was missed. Such a useful functionality!

Note: I did this from memory, so it might not be 100% correct, looking into the JDispatcher class might be a good idea if it does not work.

This can be very useful in many projects that need some simple plugin functionality specifically for that site, but making a custom plugin is way more work then it needs to be.

added 143 characters in body
Source Link
Jordan Ramstad
  • 2.9k
  • 1
  • 13
  • 31

ThisNote: I did this from memory, so it might not be 100% correct, looking into the JDispatcher class might be a good idea if it does not work. This can be very useful in many projects that need some simple plugin functionality specifically for that site, but making a custom plugin is way more work then it needs to be.

This can be very useful in many projects that need some simple plugin functionality specifically for that site, but making a custom plugin is way more work then it needs to be.

Note: I did this from memory, so it might not be 100% correct, looking into the JDispatcher class might be a good idea if it does not work. This can be very useful in many projects that need some simple plugin functionality specifically for that site, but making a custom plugin is way more work then it needs to be.

added another alternative.
Source Link
Jordan Ramstad
  • 2.9k
  • 1
  • 13
  • 31

This answer is very long and has many methods, best is at the bottom

unset($doc->_scripts[JUri::base(true)'/path/to/file.js'])

In Summary, depending on where it is added it may not be possible in the template, plugins could be the only way.

UPDATE Like I said it cannot be done with just templates, but I found a way to get around that with a simple system plugin that can be used to allow it on any site. This is something that would be useful in the core and I might try to do a pull request to get it added, though anyone is welcome to. However its unlikely to be added "next release"

class PlgSystemHooks extends JPlugin
{
    public function onAfterDispatch(){
        $app = JFactory::getApplication();
        $template = $app->getTemplate();

        if ($app->isSite())
        {
            if (file_exists(JPATH_THEMES.DIRECTORY_SEPARATOR.$template.DIRECTORY_SEPARATOR.'functions.php'))
            {
                $dispatcher = JDispatcher::getInstance();
                require_once JPATH_THEMES.DIRECTORY_SEPARATOR.$template.DIRECTORY_SEPARATOR.'functions.php';
            }
        }
    }
}

This is sort of inspired by wordpress but I was blown away when, by looking at source code I discovered it was basically completely supported in core, just the final step of defining a file in the template was missed. Such a useful functionality!

Here is how to use it.

First create a functions.php file in your template.

Next use something like this in that file.

$dispatcher->register('onBeforeCompileHead',function(){
   //your code to remove the unneeded scripts.
});

This can be very useful in many projects that need some simple plugin functionality specifically for that site, but making a custom plugin is way more work then it needs to be.

unset($doc->_scripts[JUri::base(true)'/path/to/file.js'])

In Summary, depending on where it is added it may not be possible in the template, plugins could be the only way.

This answer is very long and has many methods, best is at the bottom

unset($doc->_scripts[JUri::base(true)'/path/to/file.js'])

In Summary, depending on where it is added it may not be possible in the template, plugins could be the only way.

UPDATE Like I said it cannot be done with just templates, but I found a way to get around that with a simple system plugin that can be used to allow it on any site. This is something that would be useful in the core and I might try to do a pull request to get it added, though anyone is welcome to. However its unlikely to be added "next release"

class PlgSystemHooks extends JPlugin
{
    public function onAfterDispatch(){
        $app = JFactory::getApplication();
        $template = $app->getTemplate();

        if ($app->isSite())
        {
            if (file_exists(JPATH_THEMES.DIRECTORY_SEPARATOR.$template.DIRECTORY_SEPARATOR.'functions.php'))
            {
                $dispatcher = JDispatcher::getInstance();
                require_once JPATH_THEMES.DIRECTORY_SEPARATOR.$template.DIRECTORY_SEPARATOR.'functions.php';
            }
        }
    }
}

This is sort of inspired by wordpress but I was blown away when, by looking at source code I discovered it was basically completely supported in core, just the final step of defining a file in the template was missed. Such a useful functionality!

Here is how to use it.

First create a functions.php file in your template.

Next use something like this in that file.

$dispatcher->register('onBeforeCompileHead',function(){
   //your code to remove the unneeded scripts.
});

This can be very useful in many projects that need some simple plugin functionality specifically for that site, but making a custom plugin is way more work then it needs to be.

added 121 characters in body
Source Link
Jordan Ramstad
  • 2.9k
  • 1
  • 13
  • 31
Loading
added 841 characters in body
Source Link
Jordan Ramstad
  • 2.9k
  • 1
  • 13
  • 31
Loading
Source Link
Jordan Ramstad
  • 2.9k
  • 1
  • 13
  • 31
Loading