O'Reilly logo

PrestaShop Module Development by Fabien Serny

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required