shopware 5 subscribe to theme collect javascript code example

Example: shopware 5 subscribe to theme collect javascript

pluginPath = $p;
        $this->mainConfiguration = $c;
    }

    public static function getSubscribedEvents()
    {
        return [
            'Theme_Compiler_Collect_Plugin_Less', 'collectLess',
            'Theme_Compiler_Collect_Plugin_Javascript', 'collectJs'
        ];
    }

    public function collectLess(\Enlight_Event_EventArgs $args) {
        Shopware()->PluginLogger()->warning("Adding less...");

        $lessFiles = glob(__DIR__ . '/Resources/views/frontend/_public/src/less/*.less'); // TODO: if someone manages to get their contents into that directory...
        //$jsFiles = array(__DIR__ . '/Resources/views/frontend/_public/src/js/myFile.js');

        return new Doctrine\Common\Collections\ArrayCollection($jsFiles);
    }

    public function collectJs(\Enlight_Event_EventArgs $args) {
        Shopware()->PluginLogger()->warning("Adding js...");

        $jsFiles = glob(__DIR__ . '/Resources/views/frontend/_public/src/js/*.js'); // TODO: if someone manages to get their contents into that directory...
        return new Doctrine\Common\Collections\ArrayCollection($jsFiles);
    }
}

Tags:

Misc Example