Created
December 16, 2021 13:32
-
-
Save jonpontet/3d1ea2af21f04a34f3924c4018ecde71 to your computer and use it in GitHub Desktop.
How to add a custom JS file to the frontend of PrestaShop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function install() | |
{ | |
// Hook registration needs to go in the install function of your module | |
if ($this->registerHook('displayHeader')) { | |
return true; | |
} | |
return false; | |
} | |
/** | |
* Function called by displayHeader hook | |
*/ | |
public function hookDisplayHeader() | |
{ | |
// Add the path to your JS file | |
// path_to_modules/this_module_name/path_to_js_file.js | |
$this->context->controller->addJS(_MODULE_DIR_ . $this->name . '/file_name.js'); | |
// Optionally add some custom HTML to the HEAD tag | |
// path_to_this_file/path_to_template.tpl | |
//return $this->display(__FILE__, 'template_file.tpl'); | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment