Yohannn Posted February 23, 2023 Share Posted February 23, 2023 I have created a new module with template. I call my module and my template in my custom hook. It work fine. But I want to call another existing module in my custom hook and I don't want to override this module because if it's deleted my module will certainly crash. So there is a solution to call this existing module with my custom hook or it is simply impossible ? I try too do this manually in the back office but it's work with "displayLeftColumn" and "displayRightColumn" but not with my custom hook. Link to comment Share on other sites More sharing options...
idnovate.com Posted February 23, 2023 Share Posted February 23, 2023 Try this: $module = Module::getInstanceByName($moduleName); $module->hookXX(); or Hook::exec($hook_name, [], $id_module); Link to comment Share on other sites More sharing options...
Yohannn Posted February 27, 2023 Author Share Posted February 27, 2023 (edited) Thank you for your reply. I make some search with what you shared me and I do this : In my class : class myClass extends Module { myFunction(){ $module = Module::getInstanceByName('nameOfModuleIWant'); return $module; } } In my hook : hookDisplayMyHook(){ $this->context->smarty->assign([ 'myVariable' => $this->myClass->myFunction(), ]); return $this->display(_FILe_, 'myTemplate.tpl'); } In my template : {include file=tpl_Path_I_Want/tpl_File_I_Want.tpl' listing=$myVariable} and this work fine. Edited February 27, 2023 by Yohannn (see edit history) Link to comment Share on other sites More sharing options...
idnovate.com Posted February 27, 2023 Share Posted February 27, 2023 Although your code is incomplete, why don't you use this? hookDisplayMyHook() { $module = Module::getInstanceByName('nameOfModuleIWant'); ... $this->context->smarty->assign([ 'myVariable' => value that you need, ]); return $this->display(_FILe_, 'myTemplate.tpl'); } Link to comment Share on other sites More sharing options...
Yohannn Posted February 28, 2023 Author Share Posted February 28, 2023 Why you call your module in your hook ? And where you put your variable $module ? Me I call the module in my class in function and I call the function in my hook. What's the differents ? And what is the better solution ? Link to comment Share on other sites More sharing options...
idnovate.com Posted February 28, 2023 Share Posted February 28, 2023 As your code is incomplete, I don't know what do you need to do. I'm offering you the best solution with the information that you are posting. Link to comment Share on other sites More sharing options...
ventura Posted February 28, 2023 Share Posted February 28, 2023 Maybe with widget https://devdocs.prestashop-project.org/8/modules/concepts/widgets/ 1 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