Override Templates In Admin Controller In Prestashop

Override Templates In Admin Controller In Prestashop

We have already published several articles about overwriting templates in Prestashop. Whenever working with a live store it is possible to apply changes directly into the template. However, this is not the best way. Using this method, we will not be able to update to new versions because our modified templates will be lost which will cause bugs and errors. The modules have to be developed in such a way, so that the users are able to install them with a single click without modifying any files.

So, today we will describe 2 ways to modify a template in admin panel.

The first example:

For instance, we need to modify the template which is used in the edit product form: adm/themes/default/template/controllers/products/features.tpl

So, we rewrite the function AdminProductsController::initFormFeatures($obj)

And instead of the default template

we will use our custom template:

Quite simple, isn’t it?

The second example:

For example, we use a default Helper to generate forms in the admin panel and we need to generate a custom input which cannot be implemented by using default Prestashop templates.

A simple code of the method BelvgSearchProFilters::renderParentOnOffFields($obj)

The main specifics of this method is that it uses ‘type’ => ‘categories_select’, which can transfer HTML into the property “category_tree“.

So, these are the methods we use in our modules and we are really interested in the feedback of the community!



7 comments

  1. Hi Alex,
    Regarding your first example, there is even a simpler way to do it now in PS 1.6.
    You simply use the /override/controllers/admin/templates/ directory.

    In your case, you would put your new features.tpl file in the /override/controllers/admin/templates/products/ directory. Et voilà!

    But thanks for the tips anyway.
    Best regards.

  2. Cyd,

    Thank you for your comment, this new way is really great! But if we are talking about the module, the standard install process will not move tpl files into the override directory, and therefore it is possible that some may still need to use the “old” way.

  3. Hey,

    what about if I would like to override admin/templates/orders/_product_line.tpl ?

    Cyd example is not working. I just want to add a few html rows to _product_line.

  4. ml,

    If you need to change the template not inside the module it is better to to copy this file to override folder.

  5. Okey, so I should create folder: C:\wamp\www\ps\modules\mymodule\override\controllers\admin\templates\orders and put the _product_line.tpl file here? I have done it and after install any changes. If I check prestashop override files I even can`t see this file. Why? Should I write additional function to use it (override)? Even if I do it manuall – no effect.

  6. Hi Alex,

    I’m a bit confused. You mention that modules have to be developed in such a way that user don’t need to modify any files.
    But the first example requires that a Prestashop core file is modified, right?
    Or is something crucial escaping my attention?

    Cheers,

    Menno

Post a new comment

top