Jump to content

Change template files with my module


Recommended Posts

Hi,

 

how can I make it so that my module changes or overwrites the installed template files?

 

Specifically I want to modify product-list.tpl

 

This modification should take affect while my module is installed.

 

But once uninstalled, it should go back to normal.

 

Is there an clean and easy way to do this?

Link to comment
Share on other sites

Thanks!

 

So the short answer is: Not really.

 

The long answer is...

 

 

Old thread but someone might find this useful while Googling.

 

Actually, it is possible to "override" the theme product.tpl file from your module.

 

Your module needs to override the ProductController.php file. You need to look for the setTemplate() call in the init() function, and you can change the path of the template, which would reside somewhere in your module. If you upgrade Prestashop core, you have another overriden function you need to check and possibly revise, and you also need to make sure no other module is overriding the same function.

 

Another method is to write some code that physically copies and pastes the .tpl file to the template when the module is installed, and then reverse what you did when the module is uninstalled (which means your code would need to have taken a backup of the original file).

 

Either method is very simple and will work. Of course, I have made no assumptions of the big picture you are trying to achieve. These methods are fine for privately used modules. As long as you can keep track of your changes, you should be fine. However, if you are distributing these modules to the public, overriding the tpl file would likely break the theme as has been pointed out, because you do not know what theme they are using.

 

Perhaps an advantage of not editing the theme directly means you can encapsulate your edits neatly inside modules only so you can turn the edits on and off via the control panel, or perhaps you have conditional code that will load a different template. A more philosophical argument is that by keeping all edits in modules only, it is always clear where your changes are so easier to manage, but I'm not convinced by that argument because VCS  can easily tell you what files have been changed. If the choice was mine, I would edit the theme directly.

 
Edited by theillo (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...