Jump to content

addJS and addCSS cannot be added to Front Controller


Kathleen86
 Share

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',

        ]

        );

    }

Share this post


Link to post
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)

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More