oliver Posted June 17, 2020 Posted June 17, 2020 I am absolutely not clear on what the "best" or "correct" way is for me to add JS files to my modules. I suppose this problem can be categorized as Asset Management. There are several variables: Sometimes JS should be included in the header, sometimes before the body tag closes. Sometimes my JS has a dependency, which needs to be loaded BEFORE my JS file (e.g. jQuery) Sometimes my module has a controller from which it can load JS, sometimes it's only a hook. Sometimes I need JS on the front office (customer area) sometimes in the back office (admin area) Personally I think jQuery should be included by default, but I understand the reasons why it might not be. Over the years, I've quite a few methods of how to get things to work: public function hookDisplayBackOfficeHeader($params){ $this->context->controller->addJquery(); $this->context->controller->addJS($url); } protected function addBackOfficeMedia(){ } public function setMedia(){ } And probably a couple of other ways, including to just slap it into the tpl file... I've been really confused on this for a long time! PrestaShop 1.7 actually introduced something super useful: public function hookActionFrontControllerSetMedia(){ $this->context->controller->registerJavascript( 'title-of-script-or-lib', $path, [ 'position' => 'head|bottom', //SO USEFUL!! 'priority' => 50, //SO USEFUL!! 'inline' => false, 'server' => 'remote', 'attributes' => 'async', ] ); } Source: https://devdocs.prestashop.com/1.7/themes/getting-started/asset-management/ I thought this was a really nice, clean, long needed solution for this problem. Literally, this was probably the only good thing about PS 1.7 hahah What's the status quo about that on Thirtybees? Is there any conclusive documentation available about this?
Question
oliver
I am absolutely not clear on what the "best" or "correct" way is for me to add JS files to my modules.
I suppose this problem can be categorized as Asset Management.
There are several variables:
Personally I think jQuery should be included by default, but I understand the reasons why it might not be.
Over the years, I've quite a few methods of how to get things to work:
And probably a couple of other ways, including to just slap it into the tpl file... I've been really confused on this for a long time!
PrestaShop 1.7 actually introduced something super useful:
Source: https://devdocs.prestashop.com/1.7/themes/getting-started/asset-management/
I thought this was a really nice, clean, long needed solution for this problem.
Literally, this was probably the only good thing about PS 1.7 hahah
What's the status quo about that on Thirtybees? Is there any conclusive documentation available about this?
0 answers to this question
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now