I'm creating a custom module in Prestashop 1.7, and I've tried many solutions but nothing solved my problem.
I would add an external JS file to the header or footer of the website where the module is installed (and only when it's installed).
<script src="https://cdn.monurl.com/file.js"></script> // JS file to include
I tried to use the addJS() method in the displayHeader hook:
public function hookDisplayHeader($params)
{
if (!$this->active)
return;
$this->context->controller->addJS('https://cdn.monurl.com/file.js');
}
public function install()
{
return parent::install() && $this->registerHook('displayHeader');
}
I made a lot of tests, and the hookDisplayHeader() function is called, but my JS file doesn't appear in the <head> of my page.
The Prestashop documentation is limited, but after many researches, I think I can only use the addJS() method with internal JS files. Am I right?
How should I do to add an external JS file to my header (or footer before </body>)?