How To Create CustomCMS Hook Prestashop Module

1 OVERVIEW – Back to top

To show/display the modules on each page in PrestaShop, we need to create new Hooks and CMS pages.
Here are the steps to create a new Hook
1. Create CMS page in Preferences / Cms
2. Create new Hook in file module.php
3. Declare the created Hook in file cms.tpl
4. In module, select CMS Hook in the listbox

2 CREATE SMS PAGE – Back to top

Login your back-office then navigate to: Preferences>> CMS.

access the translation menu

Click “Add new CMS page” button.

access the translation menu

Fill the form with your information. Two required fields are Meta title and Friendly URL, set Displayed = yes. Click save button to save the information.

access the translation menu

You will see the message “Successful update”.

access the translation menu

Created page will appear on the list of pages. Note: Remember ID of the page to use in the next step

access the translation menu

3 DECLARE A FUNCTION – Back to top

Steps 1: You find the original installation directory of PrestaShop.Then go to the folder Module -> Name module. Ex: SP Search Pro module

access the translation menu

Steps 2: Find the file named module.php. Ex: spsearchpro.php

access the translation menu

Steps 3: Find $default_hook and add CustomCMS to it. Do the same thing to function_construct with $this->registerHook(‘customCMS’) at the end of function __construct

copy language

Steps 4: You declare function hookcustomCMS right after function hookDisplayHome

copy language

Copy and paste the following code:

You need to change 4 values in the above code:

  • 1 – CustomCSM page ID you created at the first step
  • 2 – Name of module. Ex: Here
  • 3 + 4 – Name of hook.

copy language

Then save the file.

Steps 5: Open file cms.tpl in the original installation directory of PrestaShop with the url prestashop\themes\default-bootstrap. Copy and paste the following code:

Steps 6: Login your back-office then navigate to: Modules>>Modules. Find the module that you want to create customCMS hook. You will see customCMS in Hook Into

copy language

End, you will get the results in the font-end look like image below:

copy language

 Wish you success !