Page 1 of 1

addStyle and addScript

Posted: Thu Apr 28, 2011 3:11 am
by scott23
I'm working on changing a megamenu into a module to help with future updates and in the process thought it would be easier to place the link to the CSS and JS script in the controller file for the module. I have read several posts about doing this but it never seems to push those links into the header. Has anyone been able to get this to work?

Scott

Re: addStyle and addScript

Posted: Thu Apr 28, 2011 3:39 am
by Xsecrets
are you putting in a module controller or one you made yourself. If it doesn't work it's generally because the child order is wrong, but this has been fixed in all the core files for several versions now.

Re: addStyle and addScript

Posted: Thu Apr 28, 2011 3:47 am
by scott23
It uses a copy of the category.php file located in catalog\controller\common and is copied into catalog\controller\module with some edits done to show the correct format for the menu.

Scott

Re: addStyle and addScript

Posted: Thu Apr 28, 2011 5:22 am
by Xsecrets
just check your childeren call with a that from a standard file from a recent version. basically the header has to be after the controller where the addstyle/addscript is called for instance if you call it in a module that is in the left column header would have to be after column_left in the childeren list.

Re: addStyle and addScript

Posted: Thu Apr 28, 2011 7:27 am
by scott23
This menu is located in the header with a newly created module location. Attached is the controller file that I am trying to add it to, so where would you put the code in at?

Re: addStyle and addScript

Posted: Thu Apr 28, 2011 7:32 am
by Xsecrets
that's not a mainpage controller. If you are adding it to the header and it's not working my guess is that you added your new module below the addscript and addstyle calls and it would need to be above for the call to get registered.

Re: addStyle and addScript

Posted: Thu Apr 28, 2011 10:04 am
by scott23
I gotcha now. I guess I thought that those could be used directly in the module controller to keep from having to edit the core files. Thanks for the help.

Re: addStyle and addScript

Posted: Thu Apr 28, 2011 10:26 am
by Xsecrets
scott23 wrote:I gotcha now. I guess I thought that those could be used directly in the module controller to keep from having to edit the core files. Thanks for the help.
they can, but from what it sounds like you have already edited the core files to add a module position in the header, but you didn't do it correctly, and the addscript from the module is not getting called until after the header has already set all the scirpts.