Jump to content

addJS and addCSS cannot be added to Front Controller


Kathleen86

Recommended Posts

Hello everybody,

The CSS and JS are not taken into account in my front controller module. What could I do ? Thank's in advance for your help.

 

Here is the code of the method setmedia:

 

public function setMedia()

    {

        parent::setMedia();

        $this->registerStylesheet(

        

            'localhost/softage/modules/aeccollaborators/views/css/my-collaborator.css',

            [

              'media' => 'all',

              'priority' => 200,

            ]

           );

        $this->registerJavascript(

        

        'localhost/softage/modules/aeccollaborators/views/js/my-collaborator.js',

        [

            'priority' => 200,

            'attribute' => 'async',

        ]

        );

    }

Link to comment
Share on other sites

For PS 1.7+ use this hook in your module's main class:

public function hookActionFrontControllerSetMedia()
        {
            Media ::addJsDef([
                'your_module_name' => $this -> context -> link -> getModuleLink($this -> name, 'display', [], true),
            ]);

            $this -> context -> controller -> registerJavascript('modules-your_module_name',
                'modules/' . $this -> name . '/views/js/front.js');
        }

It also works with hookHeader().

Edited by Rhobur (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...