Przemysław Suszek Posted January 28, 2018 Share Posted January 28, 2018 (edited) Hi, I have custom module which I run, display by type URL: http://mydomain.com/en/module/custommodule/mypage The problem I have with addJS. This is my code: public function hookBackOfficeHeader() { $this->context->controller->addJS($this->_path . '/js/configurator.js'); } public function hookDisplayHeader() { $this->context->controller->addJS($this->_path . '/js/configurator.js'); } public function hookHeader() { $this->context->controller->addJS($this->_path . '/js/configurator.js'); } public function hookActionAdminControllerSetMedia($params) { $this->context->controller->addJS($this->_path . '/js/configurator.js'); } Even I clean cache I dont see javascript file. What I did wrong ? Kind regards Edited January 30, 2018 by mr.suchy solved (see edit history) Link to comment Share on other sites More sharing options...
Nishith Nesdiya Posted January 29, 2018 Share Posted January 29, 2018 Hi... Which PS version you use ? Thanks Link to comment Share on other sites More sharing options...
Przemysław Suszek Posted January 29, 2018 Author Share Posted January 29, 2018 1.6.1.12 Link to comment Share on other sites More sharing options...
Nishith Nesdiya Posted January 29, 2018 Share Posted January 29, 2018 Hi... can you register with all hook in module install folder ? Like this public function install() { return parent::install() && $this->registerHook('header') & } and also you can set the all media file in your module front controller using this method public function setMedia() { parent::setMedia(); /* your js add here */ } Thanks Link to comment Share on other sites More sharing options...
Przemysław Suszek Posted January 29, 2018 Author Share Posted January 29, 2018 (edited) My code: public function install() { if (Shop::isFeatureActive()) Shop::setContext(Shop::CONTEXT_ALL); return parent::install() && $this->registerHook('actionAdminControllerSetMedia') && $this->registerHook('header'); } public function setMedia() { parent::setMedia(); $this->context->controller->addJS($this->_path . '/js/configurator.js'); } Clean cache. Doent work. It is possible that the problem is with bad URL to javascript file ? Edited January 29, 2018 by mr.suchy (see edit history) Link to comment Share on other sites More sharing options...
Nishith Nesdiya Posted January 29, 2018 Share Posted January 29, 2018 Hi... Front-side include your js and css file with module See demo Here is my module code with install method. public function install() { return parent::install() && $this->registerHook('header'); } Now use "header" my module public function hookHeader() { $this->context->controller->addCSS($this->_path . 'views/css/module.css'); $this->context->controller->addJS($this->_path . 'views/js/module.js'); } /* views/js/module.js */ this is your module path where is locate is js and css file. For the back-office include js nd css use "displayBackOfficeHeader" this hook Thanks Link to comment Share on other sites More sharing options...
Przemysław Suszek Posted January 29, 2018 Author Share Posted January 29, 2018 ehh still the same problem. I don't know where is the problem: \modules\mymodule\controllers\front\front.php <?php class MyFrontModuleFrontController extends ModuleFrontController { public $display_column_left = false; public $display_header = false; public $display_footer = false; public function initContent() { parent::initContent(); $this->setTemplate('front.tpl'); } } and public function install() { if (Shop::isFeatureActive()) Shop::setContext(Shop::CONTEXT_ALL); return parent::install() && $this->registerHook('header'); } public function hookHeader() { $this->context->controller->addJS($this->_path . 'js/configurator.js?v=1'); } In web I red that I should use setMedia like You said but still the problem is not solved. Link to comment Share on other sites More sharing options...
Nishith Nesdiya Posted January 30, 2018 Share Posted January 30, 2018 HI... can you share your module file ? i have check and tell you. Thanks Link to comment Share on other sites More sharing options...
Nishith Nesdiya Posted January 30, 2018 Share Posted January 30, 2018 Hi.. Hi... problem is you have hide header and footer your front controller class SamshieldHelmetsHelmetModuleFrontController extends ModuleFrontController { public $display_column_left = false; public $display_header = false; public $display_footer = false; public function initContent() { parent::initContent(); // $this->context->smarty->assign(); $this->setTemplate('helmet.tpl'); } } / Change this code public $display_header = true; public $display_footer = true; if you no need then you can include your js file is helmet.tpl file Thanks 1 Link to comment Share on other sites More sharing options...
Przemysław Suszek Posted January 30, 2018 Author Share Posted January 30, 2018 Thanks for help. Below You have my front controller. Now it is works. <?php class MyModuleFrontController extends ModuleFrontController { /*PSoft - Przemysław Suszek */ public function setMedia() { parent::setMedia(); $this->path = __PS_BASE_URI__.'modules/mymodules/'; $this->context->controller->addJS($this->path . 'js/lib/jquery-1.9.1.min.js'); $this->context->controller->addJS(__PS_BASE_URI__ . 'js/tools.js'); $this->context->controller->addJS($this->path . 'js/lib/jquery.mousewheel.js'); $this->context->controller->addJS($this->path . 'js/lib/jquery.jscrollpane.min.js'); $this->context->controller->addJS($this->path . 'js/lib/jquery.validate.min.js'); $this->context->controller->addJS($this->path . 'js/configurator.js?v=1'); } public function initContent() { parent::initContent(); $this->setTemplate('mymodules.tpl'); } } 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