I'm using a layout override to modify the cart module for Virtuemart, but the ajax request deletes part of my code when it updates. Because of this, I would like to change not only the template, but also the javascript routine the module calls.

I could get the behavior I want quickly by altering the module itself, but I was wondering if I could clone the code (which is inside a js file, it is not a part of default.php) and place it inside the override, so that I don't have to fix it every time I update Virtuemart.

Is it possible? Any ideas?


Yes, and no...

Let's start with the "no" - The Joomla core devs have created a way to inject scripts, but no (API) way to remove them.

And, "Yes" , but it's complicated....

You'll need to create a Joomla system plugin to affect the removal.

If you do it any sooner than onBeforeCompileHead - you might end up with another script injecting it again.

This example just removes a script - because I'm injecting a new one elsewhere. You could modify this to remove and replace at the same time - but that's up to you to decide.

This is how I did it for a BS3 template I wrote. I really needed to ditch the BS 2.3 javascript and replace it with BS3 javascript. The plugin was written to accommodate removing multiple javascripts, although this example only shows one.

class PlgSystemRWBS3 extends JPlugin {

function onBeforeCompileHead() {
    $doc = JFactory::getDocument();
    $cfg = JFactory::getConfig();
    $min = $cfg->get('debug', 0, 'INTEGER') ? '' : '.min';
    $remove = array(
    $this->_removeScript($doc, $remove);

private function _removeScript($o, $remove) {
    $removed = false;
    foreach($remove as $r) {
        $found = preg_grep('/'.preg_quote($r,'/').'$/', array_keys($o->_scripts));
            if(count($found) > 0) {
| improve this answer | |

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.