Book Image

PrestaShop Module Development

By : Fabien Serny
Book Image

PrestaShop Module Development

By: Fabien Serny

Overview of this book

Table of Contents (19 chapters)
PrestaShop Module Development
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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

Note

You can also add the JS file, which is in the common JS directory:

$this->context->controller->addJS(_PS_JS_DIR_.'jquery/jquery-ui-1.8.10.custom.min.js');

Or you can add the jQuery UI plugin:

$this->context...