squivo Posted May 22, 2019 Share Posted May 22, 2019 In Prestashop v1.7.5.1, I've just built `mycustommodule`. In a CMS Page, I'm trying to pull some data from mycustommodule via a hook. In the ../template/cms/page.tpl file I have: {block name='cms_content'} {$cms.content nofilter} {if $cms.id==6} <div> <h1>Here's my custom hook</h1> {hook h='displayCustomHook'} </div> {/if} {/block} In mycustommodule/mycustommodule.php, I have the hook: public function hookCustomHook( $params ){ $this->context->smarty->assign( array( 'myvariable' => 'test' ) ); return $this->display(__FILE__, '/views/templates/hook/mycustommodule.tpl'); } I cannot assign anything to smarty without getting this error (1/1) ContextErrorException Notice: Undefined property: Smarty_Internal_Undefined::$objMap in smarty_internal_extension_handler.php line 132 I even went to github and found that line of code in the Smarty class: if (isset($callback) && $callback[ 0 ]->objMap | $data->_objType) { But I feel like this is not a smarty problem -> it's something I've referenced or done or not done in the module. I have no idea what's going wrong - The whole module is working otherwise - including adding data to a custom table in the backend using an AdminController. Has anyone else had this problem? WTF Link to comment Share on other sites More sharing options...
Nishith Nesdiya Posted May 23, 2019 Share Posted May 23, 2019 Hi.. (1) First you need to register your custom hook.https://devdocs.prestashop.com/1.7/development/register-new-hook/ (2 ) use like this public function hookDisplayCustomHook( $params ){ $this->context->smarty->assign( array( 'myvariable' => 'test' ) ); return $this->display(__FILE__, '/views/templates/hook/mycustommodule.tpl'); } Thanks Link to comment Share on other sites More sharing options...
squivo Posted May 23, 2019 Author Share Posted May 23, 2019 (edited) Is dispatching the hook different than registering it? I can see my hook in the database table, and it's printing... so where would add the dispatch code? $this->hookDispatcher->dispatch(); This is my install code: public function install() { if (Shop::isFeatureActive()) Shop::setContext(Shop::CONTEXT_ALL); if (!parent::install() || !$this->registerHook('displayCustomHook') || !$this->addTab() || !$this->addMyCustomTables() ) return false; return true; } Edited May 23, 2019 by squivo the hook name was typed wrong: 'displayCustomHook' is the proper name (see edit history) Link to comment Share on other sites More sharing options...
squivo Posted May 23, 2019 Author Share Posted May 23, 2019 Oh and also there is no difference between $this->context->smarty->assign( array( 'myvariable' => 'test' ) ); and $this->context->smarty->assign( 'myvariable' => 'test' ); I still get the error. As far as I tell, my hook is registered and ready to go. 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