massimopasquali Posted April 21, 2020 Share Posted April 21, 2020 (edited) Hello, I did a custom module for prestashop 1.7.6.4, simplest to learn, and works. My module has one page .twig (modules\ps_import\views\templates\admin\import.html.twig), now I need to add one JS and one CSS, but I don't find the correct documentation online. Can you help me to find the documentation or can you give me a link to github example? tnx in advance Edited May 6, 2020 by massimopasquali (see edit history) Link to comment Share on other sites More sharing options...
fbenoist.com Posted April 22, 2020 Share Posted April 22, 2020 Hi, You can take a look at this example module: https://github.com/frederic-benoist/fbsample-botraining Link to comment Share on other sites More sharing options...
massimopasquali Posted April 22, 2020 Author Share Posted April 22, 2020 tnx I Will Link to comment Share on other sites More sharing options...
massimopasquali Posted April 22, 2020 Author Share Posted April 22, 2020 Hi, I saw your example and I would ask you: I read on prestashop doc that addcss is deprecated, but you in your had used addCss. Is corret used addCss, there is onother way? public function hookDisplayBackOfficeHeader() { // Use addCss : registerStylesheet is only for front controller. $this->context->controller->addCss( $this->_path.'views/css/fbsample_botraining.css' ); } Link to comment Share on other sites More sharing options...
fbenoist.com Posted April 22, 2020 Share Posted April 22, 2020 The function is deprecated on the front office (FrontController). You can continue to use it in the back office. Link to comment Share on other sites More sharing options...
massimopasquali Posted April 22, 2020 Author Share Posted April 22, 2020 Ok I have done some tests and if I try to register my hook into the Install method It doesn't work, also the package is istalled. The JS is like not exist: public function install() { if (Shop::isFeatureActive()) { Shop::setContext(Shop::CONTEXT_ALL); } if (!parent::install() || !$this->registerHook('leftColumn') || !$this->registerHook('header') || !Configuration::updateValue('IMPORT_DATA_NAME', 'ps_importdata') ) { return false; } return parent::install() && $this->installTab() && $this->hookDisplayBackOfficeHeader(); } private function installTab() { $tabId = (int) Tab::getIdFromClassName('ImportDataPantheraController'); if (!$tabId) { $tabId = null; } $tab = new Tab($tabId); $tab->active = 1; $tab->class_name = 'ImportDataPantheraController'; $tab->name = array(); foreach (Language::getLanguages() as $lang) { $tab->name[$lang['id_lang']] = 'Import Data Panthera'; } $tab->id_parent = (int) Tab::getIdFromClassName('AdminParentModulesSf'); $tab->module = $this->name; return $tab->save(); } public function hookDisplayBackOfficeHeader() { $this->context->controller->addJS( $this->_path.'views/js/functions.js' ); } INSTEAD IF I REGISTER MY HOOT LIKE THAT IT'S WORK public function install() { if (Shop::isFeatureActive()) { Shop::setContext(Shop::CONTEXT_ALL); } if (!parent::install() || !$this->registerHook('leftColumn') || !$this->registerHook('header') || !Configuration::updateValue('IMPORT_DATA_NAME', 'ps_importdata') ) { return false; } $this->hookDisplayBackOfficeHeader() return parent::install() && $this->installTab(); } Can you tell me why? tnx in advance Link to comment Share on other sites More sharing options...
fbenoist.com Posted April 22, 2020 Share Posted April 22, 2020 When you register your module on a hook, the function hookXXXX with XXX corresponding to the name of the hook is automatically called by PrestaShop when the hook is triggered. DispalyBackOfficeHeader is triggered when PrestaShop generates the <head></head> section of a page on the back office. The addJS function allows you to add a js file to the page. If you call the addJS function when installing the module, the addition of the JS file is not taken into account since the header of the page is not generated after but before the execution of the install() function. Link to comment Share on other sites More sharing options...
massimopasquali Posted May 5, 2020 Author Share Posted May 5, 2020 [SOLVED] Link to comment Share on other sites More sharing options...
SmartDataSoft Posted August 12, 2021 Share Posted August 12, 2021 Hello, This module can help to add js and css Thank you 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