Custom Hooks in Prestashop 1.7 - module

I try to create a custom Hook for Prestashop 1.7.0.3 for the slider module. I insert:
displaySlider:
- ps_imageslider
on theme.yml file on block “hooks”.
Then insert:
{if $page.page_name == 'index'}
{hook h='displaySlider'}
{/if}
on theme/templates/layouts/layout-both-columns.tpl file between header and section id=”wrapper” tags. According to this article: Custom Hooks in Prestashop 1.7 everything will work ok but the hook is not shown on available hooks when i try to change slider module position from the backend.

I was working today on the same issue.
And i succeed to make it appear, it is probably not the good way and i hope it is not the good way because it is weird.
In your theme.yml you have to set your hook like this :
global_settings:
hooks:
custom_hooks:
- name: displayFooterBefore
title: displayFooterBefore
description: Add a widget area above the footer
And if you wanna see your hook in the position page, you have to switch to a other template and back to your one. (Kind of refresh)
You can also check the incomplete doc from Prestashop :
http://developers.prestashop.com/themes/hooks/index.html
I hope there is a another way to refresh hooks in this page...

So just to be clear. To add a new hook in Prestashop.
In \themes\yourTheme\config\theme.yml you add
custom_hooks:
- name: displayYourCustomHook
- title: displayYourCustomHook
- description: This is a Custom hook
In the same file, in the section modules_to_hook:
displayYourCustomHook:
- ps_moduleIwantoHook
- ps_anotherModuleIwantToHook
Wherever in your .tpl files you want to add your hook:
...
{hook h='displayYourCustomHook'}
...
Finally, from you backoffice, you change from your current theme to a differente one, and then save. After that, you change to the previous theme (the theme you actually want to use), save again and your hook should be visible. This is done with the aim of "refreshing" the hooks that your Prestashop site recognasizes.
This is working in Prestashop 1.7.7

I spent a lot of time looking for why my custom hook did not appear on the front, thanks for the tip.
In order to improve the process, you can use the reset button in appearance > themes & logo.
This avoids having to activate another theme.

I see I voted myself for the accepted solution 2 years ago, but now came up with a much better solution.
According to Prestashop 1.7 hooks doc all you have to do is to register your hook as any other normal and it will be automatically created. So paste something like:
$this->registerHook('displayAtSpecificPlace');
in your module install() and reinstall the module.

Related

Hook not visible and modules issue

Goodmorning everyone. I'm going crazy behind a very simple new hook.
I just wanted to add the share buttons in the blog articles, I added the hook in theme.yml as shown in the image, I reset the theme and the module but nothing to do, I don't see the hook if I try to insert the module.
Moreover from this insertion onwards I am no longer able to reset or uninstall the module, it returns me the error you see in the image. What am I doing wrong?
img01
img02
Check if your hook exists in the ps_hooks tables if not add it there.
You need to register it in the ps_hooks database,maybe the ideal can be to create a module, and in the installation register the hook and assign a template that shows what you need in the hook.
Prestashop documentation

Prestashop 1.7.6.5 create custom hook

I am trying to add new custom hook:
theme.yml
custom_hooks:
- name: displayUnderTop
title: displayUnderTop
description: Add main menu in the header
and view:
{hook h='displayUnderTop'}
but in admin dashboard I don't see new hook. I tried to recompile template files but to no avail. How to make this hook appear on the "positions" list?
Ok Solved:
i just unzip other theme, changed to new, and change back to classic theme. It work's :)

Prestashop 1.6 Several module config pages

I am looking for way how to split my prestashop 1.6 module configuration page to several pages, because it's too long in current state. Is there something like menu/tabs helper? I will be glad for any recommendetions.
I think these Using the HelperOptions class, Using Bootstrap (check below in Navigation, tabs and menus: nav, nav-tabs classes) and maybe this Using jQuery and jQueryUI will helpful.

Prestashop Quick search block hook

i have very strange problem with latest version of prestashop installed when i unhook quick search block from displayTOP then slider and products got disturbed on page then i have to disable Quick search block from modules after that it works fine.
actually i want to display Quick search block separately on top using header.tpl file with
method
{include file=$tpl_dir./modules/blocksearch/blocksearch-top.tpl}
kindly help me to resolve this issue i'm customizing the default-bootstrap theme and using prestashop 1.6.0.9
Regards
You may create a custom hook and attache the module quick search block to this hook and in the tpl call your new hook where you want like ! {HOOK_YOURHOOK}
in your module :
public function hookDisplayQuickSearch($params)
{
$this->hookTop($params)
}
in header.tpl add
{HOOK_DISPLAYQUICKSEARCH}
Notice : i didn't try the code

Joomla question about custom module

I'm very new to Joomla. I have a question about components/modules.
I'm doing the development of a site for a firm and they provided me with custom news releases component that's supposed to show on the home page. From what I've seen, I can call modules to a page with "" based on their position.
Do I do the same sort of thing to get this component to display? Can anyone help me out please. Let me know if I'm not being clear.
EDIT: I figured out that I have to add this as a menu item, but this makes it into it's own page. I want this just as a module on the right of the home page. What do I need to do to achieve this?
Thank you
if this is a component than you won't be able to display it in a module position. You will have to write a new module to do that or use some modules which wrap around other types of content. See here, maybe this plugin will fit.
If this is a component you can also use the Component Loader extension to load the component output in a module position.
http://extensions.joomla.org/extensions/core-enhancements/embed-a-include/10721