Jump to content

Overriding core template files from module


Numsu
 Share

Recommended Posts

I'm a learning addon developer. I have been trying to solve this for a long time, how do you properly override a core template file from a module? At the moment I'm overriding the entire file by copying the template file in the override folder from my module on installation:

From:

/modules/<module>/views/templates/admin/products/informations.tpl

To:

/override/controllers/admin/templates/products/informations.tpl

Overriding the whole file just to add an input field seems pretty rough though.

 

 

This works just fine, but I'm worried because if the user installs some other module that wants to use the same file and it corrupts or Prestashop's new version changes the file and it doesn't support the new version anymore. In every way that feels like a dirty solution to the problem.

 

Is there a way to override just a part of the file and maybe directly from the module folder? Is there any better way to do this? How do you do this?

Edited by Numsu (see edit history)

Share this post


Link to post
Share on other sites

Nemo1 wrote something about it. Not sure if it answers your question:

 

http://nemops.com/override-prestashop-modules-core/#.VU3k3NOqqko

 

 

Otherwise contact him and continue the discussion :-)

 

 

My 2 cents,

pascal.

 

Hi pascal!

 

Than you for your response, but that describes how to override modules' core files, but the question I had was about overriding Prestashop's own core template (.tpl) files.

Share this post


Link to post
Share on other sites

Hi Numsu,

 

Sorry, didn't read well enough. PrestaShop makes use of Smarty. Since Smarty 3, there is a possibility to override parts of a template, using "Smarty Inheritance". In short, you can define blocks of code, name them and then replace these blocks of code in an 'extended' version of the original file. See te link for more detail.

 

PrestaShop only sparingly makes use of this as yet, and sometimes in a way that hardly made much sense to me for now, as I saw them use it by surrounding the full tpl contents by the {block} .. {/block}  tags. Maybe to get the option to extend the same file in different ways or so...

 

Any way, most of the core files don't use these {block} tags as yet, so this will not be an option for now.

 

 

I don't see much other ways than just override them in full for now,

 

pascal.

Share this post


Link to post
Share on other sites

  • 3 years later...
On 5/11/2015 at 8:06 PM, PascalVG said:

Hi Numsu,

 

Sorry, didn't read well enough. PrestaShop makes use of Smarty. Since Smarty 3, there is a possibility to override parts of a template, using "Smarty Inheritance". In short, you can define blocks of code, name them and then replace these blocks of code in an 'extended' version of the original file. See te link for more detail.

 

PrestaShop only sparingly makes use of this as yet, and sometimes in a way that hardly made much sense to me for now, as I saw them use it by surrounding the full tpl contents by the {block} .. {/block}  tags. Maybe to get the option to extend the same file in different ways or so...

 

Any way, most of the core files don't use these {block} tags as yet, so this will not be an option for now.

 

 

I don't see much other ways than just override them in full for now,

 

pascal.

 

Hi PascalVG,

thanks for your explanation. This is Ok when our module wants to use a template file. But what if (think about that) a template file (core template file) is used by a core class/controller. What if we want to modify a core template file which is used by core functionality.

E.g: CustomerForm.php uses customer-form.tpl, and we want to override the customer-form.tpl by a module

I think it is not possible at all!

 

  • Like 1

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More