Adding CSS and JS in your module
We will now look at two new functions, which will permit you to add CSS and JS in your module:
$this->context->controller->addJS($this>_path.'views/js/mymodcomments.js'); $this->context->controller->addCSS($this->_path.'views/css/mymodcomments.css', 'all');
You will probably ask yourself why use these methods when you can just add the link to your CSS and JS directly in your module templates. The reasons are as follows:
- It makes your module compliant with the CCC option in Advanced parameters | Performance. This option is used to dynamically merge all the CSS files and JS files together.
- It avoids including the same JS file several times (for example, if you need a specific jQuery UI plugin already used by another ...
Get PrestaShop Module Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.