ithil
ithil

Reputation: 1758

How to add files to a PrestaShop theme without "hacking" the core

I am working on an web built in PrestaShop that needs some re-design.
I have made a copy of their theme and I am working there. Now I need to add some javascript files and they need to be included in all my theme pages.

I have read similar questions here and looked for info and basically I have found two solutions proposed:

1) Add the file directly into your HEAD.tpl using something like {$base_dir}
(explained here: Prestashop root directory)

2) Add the files in the FrontController.php (overrides/classes) with a new setMedia() function
(explained here: http://tinyurl.com/cxucwq7)

The second solution seems the most recommended one but when I open the FrontController.php I see the following warning:

* Do not edit or add to this file if you wish to upgrade PrestaShop to newer versions in the future.

So I'm a bit confused now. Is it safe to edit this file? How about future upgrades, will they overwrite any changes made there? Isn't it safer to add them to your themes header.tpl and not affect the core of the cms?

(This is my first question here, I tried to follow the guides but I would appreciate any comments on how can I improve it, thank-you!)

Upvotes: 3

Views: 3309

Answers (1)

romainberger
romainberger

Reputation: 4558

It is totally safe to use the override file, and that's why they exist. I have used them in every Prestashop I made and they've never had been replaced in an update. The text they put is for the license, they probably just copy/paste it everywhere.

I wouldn't recommend manually adding the files to the header.tpl. It will work, but the advantage of adding it with the Tools::addJs() method is that the script will be concatenated with all the other scripts.

Upvotes: 3

Related Questions