Pedro Posted June 23, 2018 Share Posted June 23, 2018 Hi, I'm creating a module that needs to include certain script at the product page. I'm using the `hookDisplayFooterProduct` for that: public function hookDisplayFooterProduct() { $this->context->smarty->assign( array( 'some_key' => Configuration::get('SOME_KEY'), ) ); $this->context->controller->addJS($this->_path.'view/js/something.js'); return $this->display(__FILE__, 'html.tpl'); } What I'm trying to do is to include an html snippet at the 'displayFooterProduct' and to add a script to the bottom of the page. The html part works but the script is not included. What I'm doing wrong? Thanks, Pedro Link to comment Share on other sites More sharing options...
NemoPS Posted June 23, 2018 Share Posted June 23, 2018 Try this if(isset($this->context->controller->php_self) && $this->context->controller->php_self == 'product') It should only target the product page Link to comment Share on other sites More sharing options...
Pedro Posted June 26, 2018 Author Share Posted June 26, 2018 Thanks @NemoPS, I added that code to my hookDisplayHeader and it works (I know because I display something with var_dump) but I'm still unable to include include the script with $this->context->controller->registerJavascript('remote-mymodule-js', 'https://.....', ['position' => 'bottom', 'priority' => 150]); I'm using prestashop 1.7. Is there any public API documentation for methods like registerJavascript? Link to comment Share on other sites More sharing options...
NemoPS Posted June 26, 2018 Share Posted June 26, 2018 The function is actually $this->context->controller->addJS, I have never used that registerJavascript one honestly. I would recommend using a separate js instead of assigning it from php anyway. If you really need to, use addJSDef(); Link to comment Share on other sites More sharing options...
Pedro Posted June 26, 2018 Author Share Posted June 26, 2018 I also tried with addJS without any success. public function hookDisplayHeader() { $this->context->controller->addJS($this->_path.'view/js/something.js'); $this->context->smarty->assign( array( 'my_module_key' => Configuration::get('my_module_key') ) ); return $this->display(__FILE__, 'test.tpl'); } I expect to see something.js being included on the page. I'd disabled all caches, hit reset on the module. As a workaround I fixed my problem by adding a <script> tag with smarty. Link to comment Share on other sites More sharing options...
NemoPS Posted July 2, 2018 Share Posted July 2, 2018 That's the correct way to do it actually, but I think you need a / before view/ Link to comment Share on other sites More sharing options...
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