Skip to end of metadata
Go to start of metadata

Using helpers to overload a back-office template

Back-office template architecture

The back-office templates are stored in the admin/themes/default/template folder, but several locations can have an impact:

  • admin/themes/default/template/helpers/type_of_the_helper/: templates that are directly called by helpers if there is no template overloading.
  • admin/themes/default/template/controllers/name_of_the_controller/: templates that are directly overloaded by a controller.
  • override/controllers/admin/templates/name_of_the_controller/: overloading folder for templates that already exist in admin/themes/default/template/controllers/name_of_the_controller/



Create this test table in your MySQL database:

Create this Test class:

Example 1: Using templates for helpers within a controller

We are going to create a controller by using the default helpers' templates.

First, we create a Test controller:

Here is the result of the list generation (renderList() method):

Here is the result of the form generation (renderForm() method):

Example 2: Overloading a helper template

You might want something different than what the default helper template provide. Thankfully, you can overload the helps template themselves!

First, you need to create a folder in the admin/themes/default/template/controllers/ folder. Let's call it /test.
This folder name is the name of the controller without the "Admin", "Controller" and "Core" sections. For example:

  • AdminTestControllerCore -> admin/themes/default/template/controllers/test/
  • AdminTestPrestashopControllerCore -> admin/themes/default/template/controllers/test-prestashop/

You can change the name of the folder if you put this code in the constructor:

...or you could define a new architecture with subfolders by putting this code in the constructor:

Here is how you can overload a form's .tpl file (in admin/themes/default/template/controllers/test/helpers/form/form.tpl):

Here is the result:

Example 3: Overloading an existing template

You might want to overload a template using a controller. In this case, you just have to put the overloaded file in the following folder: override/controllers/admin/template/

For instance, let's say you want to add a message in the General Preferences page. You must have add the following file in this location: override/controllers/admin/templates/preferences/helpers/options/options.tpl

Here is the result:


  • No labels