Jump to content

override admin template tpl file


Recommended Posts

Hi to all,

 

i need to override an admin template file,the tpl files is located here:

 

ADMINFOLDER/themes/default/template/controllers/orders/_product_line.tpl

 

browsing the forum i have found this topic and i have create the tpl file here:

 

mymodule/views/templates/admin/_configure/controllers/orders/_product_line.tpl

 

but it doesn't work.

 

where is the error?

Link to comment
Share on other sites

Are you developing a module? I guess so if you are placing a file in "mymodule/views/templates/admin/_configure/controllers/orders/_product_line.tpl". Therefore, can you please share the code with us so we can have a look?

 

If you are not developing a module then it is obvious putting the file in that directory will never work as it won't be link with any module, hence pointless. In that case, you need to update _product_line.tpl directly.

 

Does that make sense?

 

BR,

RaPhiuS

Link to comment
Share on other sites

Are you developing a module? I guess so if you are placing a file in "mymodule/views/templates/admin/_configure/controllers/orders/_product_line.tpl". Therefore, can you please share the code with us so we can have a look?

 

If you are not developing a module then it is obvious putting the file in that directory will never work as it won't be link with any module, hence pointless. In that case, you need to update _product_line.tpl directly.

 

Does that make sense?

 

BR,

RaPhiuS

 

yes i'm developing a module.

My module override some function of the order controller.

The controller override work fine, but the tpl doesn't.

I have to declare something in the mymodule.php file?

Link to comment
Share on other sites

The only thing I can think of here, to get the file you are willing to include from your module folder, is to check the createTemplate() method declared in the AdminController.php to see where it picks up the _product_line.tpl.

 

I can see in the AdminOrdersController a call to createTemplate with this file:

 

$view = $this->createTemplate('_product_line.tpl')->fetch();

 

I guess it's only a matter of understanding which directory to put the file in and you will be done.

 

I never did override any core controller from Prestashop so that is all I can think of... Hope this helps...

 

BR,

RaPhiuS

Link to comment
Share on other sites

  • 1 month later...

Hello,

 

Not sure if this is still needed but in case. I am using PS 1.5.3.1. Let's say I want to overrider the admin login template. Looking the code, I can see that it will look in those folder:

 

override/controllers\admin\templates\login\content.tpl

{admin}/themes/default\template\controllers\login\content.tpl

 

It means that if you want to override an admin template for another module that is not yours, you will have to put your files under: override\controllers\admin\templates\{controllers tpl folder}

 

Hve a nice day!

Link to comment
Share on other sites

  • 7 months later...

 

Hello,

 

Firstly put your _product_line.tpl file in your module. and call this function (override_file) in install function.

 

public function override_file(){
 
$dir = _PS_ROOT_DIR_."/override/controllers/admin/templates/orders";
 
if(!file_exists($dir) && !is_dir($dir)){
@mkdir(_PS_ROOT_DIR_."/override/controllers/admin/templates/orders", 0777);
}
 
$fileData = file_get_contents(dirname(__FILE__).'/_product_line.tpl');
 
$filepath = _PS_ROOT_DIR_."/override/controllers/admin/templates/orders/_product_line.tpl";
 
file_put_contents($filepath,$fileData);
}

 

 

I'm having the same problem and can't figure it out.

 

But, how does this help? All it does is copy the file to the place where I've already put it.

What you are suggesting is that Prestashop does not use the file in the /override path, but the file in the /modules path, which I don't think is true.

 

I need Prestashop to actually use the override file in stead of the original.

 

Any one?

Link to comment
Share on other sites

  • 3 weeks later...

Bonjour,

 

La méthode proposée par Prestashop Dev fonctionne impec, je viens de l'utiliser avec succès sur un module en développement pour PS 1.5.

 

Merci pour le tuyau.

 

Je suis juste étonné, qu'en plaçant mon fichier tpl dans modules/monmodule/override/controllers/admin/templates/orders/monfichier.tpl, celui ne soit pas automatiquement copier dans le dossier override de PS, comme c'est le cas pour les fichiers php de surclassement des classes et controllers.

 

Je cherche à présent à comprendre comment surclasser les fichiers js comme /js/admin-product.js

 

Crdlt

Franck

Link to comment
Share on other sites

  • 4 months later...

I'm having the same problem and can't figure it out.

 

But, how does this help? All it does is copy the file to the place where I've already put it.

What you are suggesting is that Prestashop does not use the file in the /override path, but the file in the /modules path, which I don't think is true.

 

I need Prestashop to actually use the override file in stead of the original.

 

Any one?

 

Hi, in order to override existing .tpl on admin site (ie: order details view) you should copy:

/{admin}/themes/default/template/controllers/orders/helpers/view/view.tpl

to

/override/controllers/admin/templates/orders/helpers/view/view.tpl

and of course, after amending the second one you should be able to see changes.

  • Like 2
Link to comment
Share on other sites

@martino7777

 

What you recommend is working:

 

/{admin}/themes/default/template/controllers/orders/helpers/view/view.tpl

to

/override/controllers/admin/templates/orders/helpers/view/view.tpl

 

Did you try

{admin}/themes/default\template\controllers\orders\_product_line.tpl

to

override/controllers/admin/templates/orders/_product_line.tpl

 

I tried but nothing happened.

Link to comment
Share on other sites

@martino7777

 

What you recommend is working:

 

/{admin}/themes/default/template/controllers/orders/helpers/view/view.tpl

to

/override/controllers/admin/templates/orders/helpers/view/view.tpl

 

Did you try

{admin}/themes/default\template\controllers\orders\_product_line.tpl

to

override/controllers/admin/templates/orders/_product_line.tpl

 

I tried but nothing happened.

 

Thanks for ask, @Realayumi.

all paths to tpl files with names, starting with underscore "_" are defined within their parent tpl files.

For example, if you need to change _product_line.tpl, firstly you have to override view.tpl for orders in /override/controllers/admin/templates/orders/helpers/view/view.tpl

secondly, change path to new _product_line.tpl

defined as {include file='controllers/orders/_product_line.tpl'}

to {include file='../../_product_line.tpl'}

 

Please notice, that _product_line.tpl is stored in /override/controllers/admin/templates/orders

  • Like 3
Link to comment
Share on other sites

  • 1 month later...

Thanks for ask, @Realayumi.

all paths to tpl files with names, starting with underscore "_" are defined within their parent tpl files.

For example, if you need to change _product_line.tpl, firstly you have to override view.tpl for orders in /override/controllers/admin/templates/orders/helpers/view/view.tpl

secondly, change path to new _product_line.tpl

defined as {include file='controllers/orders/_product_line.tpl'}

to {include file='../../_product_line.tpl'}

 

Please notice, that _product_line.tpl is stored in /override/controllers/admin/templates/orders

This post really helped. Thank you :)

Link to comment
Share on other sites

  • 4 months later...

Hi mging80, i don't know if you have resolved this issue.

if you want to use your template file, you need two things an override of the controller, precisely override the method you need, renderView, renderList, and a directory where to store the template file.

 

In the overriden method, you can use this code:

public function <overridden_method>()
{
parent::<overridden_method>();

$tpl_file = _PS_MODULE_DIR_.'/<module_name>/views/template/admin/<controller_name>/<template_file>.tpl';

$tpl = $this->context->smarty->createTemplate($tpl_file, $this->context->smarty);

$tpl->assign($this->tpl_view_vars);

return $tpl->fetch();
}

Hope this can help.

 

Best regards

Link to comment
Share on other sites

  • 1 year later...
public function <overridden_method>()
{
parent::<overridden_method>();

$tpl_file = _PS_MODULE_DIR_.'/<module_name>/views/template/admin/<controller_name>/<template_file>.tpl';

$tpl = $this->context->smarty->createTemplate($tpl_file, $this->context->smarty);

$tpl->assign($this->tpl_view_vars);

return $tpl->fetch();
}

 

I tried, but it did not run, Can you help me? My version is 1.6.x and I want to override informations.tpl in admin/themes/default/template/controller/product/informations.tpl

public function renderView()
    {
        parent::renderView();
        
        $tpl_file = _PS_MODULE_DIR_.'/hotpro/override/controllers/admin/templates/products/informations.tpl';

        $tpl = $this->context->smarty->createTemplate($tpl_file, $this->context->smarty);

        $tpl->assign($this->tpl_view_vars);

        return $tpl->fetch();
    }

    public function renderList()
    {
        parent::renderList();
        $tpl_file = _PS_MODULE_DIR_.'/hotpro/override/controllers/admin/templates/products/informations.tpl';

        $tpl = $this->context->smarty->createTemplate($tpl_file, $this->context->smarty);

        $tpl->assign($this->tpl_view_vars);

        return $tpl->fetch();
    }
Link to comment
Share on other sites

×
×
  • Create New...