Jump to content

Adding an existing module to a new hook


Recommended Posts

Ive created a new hook and I want to add an existing module (blocktopmenu) to that hook.

The hook's name is: topMenu

Ive added this to blocktopmenu.php:

public function hookTopMenu($param)
 {
global $smarty;
  $this->makeMenu();
  $smarty->assign('MENU_SEARCH', Configuration::get('MOD_BLOCKTOPMENU_SEARCH'));
  $smarty->assign('MENU', $this->_menu);
  $smarty->assign('this_path', $this->_path);
  return $this->display(__FILE__, 'blocktopmenu.tpl');
 }

 

Ive added the module to the new hook in Modules --> Position.

 

Then Ive added this to override/classes/FrontController.php:


function displayHeader(){ parent::displayHeader();
		
self::$smarty->assign(array(
'HOOK_HEADER' => Module::hookExec('header'),
'HOOK_TOP' => Module::hookExec('top'),
'HOOK_TOP_MENU' => Module::hookExec('topMenu'),
'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn')
));
}

Finally in themes/mytheme/header.tpl I have:

<div class="my_top_menu">{$HOOK_TOP_MENU}</div>

But nothing happens... the output is:

<div class="my_top_menu"></div>

Any idea how to get it ?

Thanks!

Link to comment
Share on other sites

what is the content of 'blocktopmenu.tpl'?

Ive put a dummy text...

This is the menu

 

What is the content of override/classes/FrontController.php? Only code that you post in this topic? Nothing like FrontController extends FrontControllerCore etc?

 

The full content is:

 

 

class FrontController extends FrontControllerCore {
	public function setMedia() {
		parent::setMedia();

		/*
		* Use Google Libraries API to host jQuery
		*/
		global $js_files;
		$index = array_search(_PS_JS_DIR_ . 'jquery/jquery-1.4.4.min.js', $js_files);
		if ($index !== false){
			array_splice($js_files, $index, 1, array('//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js'));
		} else {
			$js_files[] = '//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js';
		}
	}
	function displayHeader(){
		parent::displayHeader();

		self::$smarty->assign(array(
			'HOOK_HEADER' => Module::hookExec('header'),
			'HOOK_TOP' => Module::hookExec('top'),
			'HOOK_TOP_MENU' => Module::hookExec('topMenu'),
			'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn')
		));
	}

}

Link to comment
Share on other sites

I observe that if I put this:

 

 

public function hooktopMenu($param)
 {
   global $smarty;
   $this->makeMenu();
   $smarty->assign('MENU_SEARCH', Configuration::get('MOD_BLOCKTOPMENU_SEARCH'));
   $smarty->assign('MENU', $this->_menu);
   $smarty->assign('this_path', $this->_path);

   $length = $this->display(__FILE__, 'blocktopmenu.tpl');
   echo "LENGTH:".strlen($length);
   return $length;
 }

 

It displays:

 

LENGTH: 16

 

but the code isnt display where I put {$HOOK_TOP_MENU} :(

Link to comment
Share on other sites

ok, If I put this:

'HOOK_TOP_MENU' => Module::hookExec('topMenu'),

 

in

classes/FrontController.php

 

it works.

 

but it doesnt work if I put in:

override/clases/FrontController.php

 

It looks like override isnt working... I noticed that override doesnt work if I modify a module content in themes/mytheme/modules/anymodule/anymodule.tpl

 

Im a prestashop noob... any idea how to get override working ?

 

Thanks

Link to comment
Share on other sites

 

 

It looks like override isnt working... I noticed that override doesnt work if I modify a module content in themes/mytheme/modules/anymodule/anymodule.tpl

 

Im a prestashop noob... any idea how to get override working ?

 

Thanks

 

Some modules when you put them within themes directory and overrided them worked by default.

However, as for using blocktopmenu module -i.e putting it in the modules folder within mytheme's directory , it doesn't appear even at the BO.

 

It only appears on BO modules list in "other modules" after I made a copy into the root /modules/blocktopmenu. ( I used prestashop1.4.8.2 and blocktopmenu version 1.3)

Edited by halennoor (see edit history)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...