Jump to content

Header hook in mobile template


maluma

Recommended Posts

Hey guys,

 

i'm having troubles with a module in PrestaShop 1.5.6.1 when trying to use the header hook in the default mobile template.

 

In presta/themes/default/mobile/header.tpl there is

{$HOOK_MOBILE_HEADER}

I tried to use this module similar to the HOOK_HEADER in the regular template.

 

In the module I am registering the hooks

public function install()
{
	if (!parent::install() ||
		!$this->registerHook('header') ||
		!$this->registerHook('mobileHeader'))
		return false;
	return true;
}

and then using these functions to have some output

public function hookDisplayHeader()
{
    return "<!-- Hello World -->";
}
public function hookDisplayMobileHeader()
{
    return "<!-- Hello World -->";
}

The regular hook is working but the mobile isn't. I also couldn't find the mobile header hook in the databasetable pre_hook.

 

Has anyone experience with that?

 

Greetings

Maluma

Link to comment
Share on other sites

There are two ways I could see this happening:

 

Differences between 1.5 and 1.6

I was looking at the GitHub for PrestaShop and in 1.6 they changed how the displayMobileHeader hook is used.

 

In 1.5: https://github.com/PrestaShop/PrestaShop/blob/1.5.6.1/classes/controller/FrontController.php#L437

In 1.6: https://github.com/PrestaShop/PrestaShop/blob/1.6/classes/controller/FrontController.php#L437

 

In 1.5 it used "getMobileDevice()" to determine to run the hook or not, whereas in 1.6 it looks like it checks if the theme being used is a mobile theme. The difference coule be that if you're using a non-mobile device to test the mobile site?

 

Added a hook without reinstalling module

Did you change your install() method to add the hook but have not re-installed the module? You can always check the ps_module_hook table to see if your module has the hook or check the back office to see if the module position has that module.

Link to comment
Share on other sites

Did you change your install() method to add the hook but have not re-installed the module?

 

Sometimes I would like to bang my head against the wall! I haven't changed the install method in a while and totally forgot to reinstall.

 

But it didn't solve the complete problem. I also had to change

!$this->registerHook('mobileHeader'))

to

!$this->registerHook('displayMobileHeader'))

Thanks a lot!!!!

  • Like 1
Link to comment
Share on other sites

Derp I should have noticed the hook name being wrong! I make the same mistakes with forgetting to re-install my module. I have a script I have been working on called "prestamod" that wraps the module development in a Makefile, and one of the build operations I have is "hotplug" where I uninstall it and re-install it.

 

I will try to get that on GitHub and put a link here on the forums maybe others will find it useful.

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...