be_tnt Posted January 30, 2013 Share Posted January 30, 2013 (edited) Hello! I am trying to override the form.tpl to add a new input type (linked to a module I am developping). I read the documentation but I do not see how to do it. In any solution, I would need a controller but in my case, I do not have one. So is there a way to override this form.tpl without a controller and without writting directly in the original file? Edited February 1, 2013 by be_tnt (see edit history) Link to comment Share on other sites More sharing options...
be_tnt Posted January 31, 2013 Author Share Posted January 31, 2013 Progress ... I have created the controller. To override an helper form, I have to place the overriden file under (in my case): admin\themes\default\template\controllers\{name of my controller}\helpers\form. There I have created the form.tpl with following content: {extends file="helpers/form/form.tpl"} {block name="input"} {if $input.type == 'filesb'} {if isset($input.display_image) && $input.display_image} {if isset($fields_value.image) && $fields_value.image} <div id="image"> {$fields_value.image} <p align="center">{l s='File size'} {$fields_value.size}kb</p> </div><br /> {/if} {/if} <input type="file" name="{$input.name}" {if isset($input.id)}id="{$input.id}"{/if} /> {if !empty($input.hint)}<span class="hint" name="help_box">{$input.hint}<span class="hint-pointer"> </span></span>{/if} {else} {$smarty.block.parent} {/if} {/block} In my controller, in fields_form definition, I have: 'input' => array( array( 'type' => 'filesb', 'label' => $this->l('Select a file:'), 'desc' => $this->l('Banner picture. Extension allowed: jpeg, png, jpg, gif.'), 'name' => 'image', 'required' => false, 'lang' => true, 'display_image' => true, ), But when I render the form in BO, the filesb does not seem to be recognized Nothing appears in place of filesb. Did I miss something? I read 10 times the documentation / see examples in existing files but I can not see what I miss. Any idea? Link to comment Share on other sites More sharing options...
be_tnt Posted January 31, 2013 Author Share Posted January 31, 2013 ok found the issue: the controller folder nama had a typo. This is now working. But checking the code, I see that it's possible to have the form.tpl override in my module folder. The condition is the following: class: HelperCore function: createTemplate else if ($this->module) { $override_tpl_path = _PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/_configure/'.$this->override_folder.$this->base_folder.$tpl_name; } My controller is an instance of AdminController. How can I get the module information??? Link to comment Share on other sites More sharing options...
be_tnt Posted February 1, 2013 Author Share Posted February 1, 2013 I fixed my original issue about the override form.tpl for the module. The form.tpl overriden file should be placed under G:\Eclipse_workspace\cristal-shop\modules\{module name}\views\templates\admin\_configure\helpers\form For the controller solution, I think it's not possible to have the overriden file under the module folder (at least, I did not find a way to do it). 1 Link to comment Share on other sites More sharing options...
atogeek Posted February 7, 2013 Share Posted February 7, 2013 Hi, I try to oveload 'list.tpl' in my module. I put the overriden file in this directory : - MODULE/views/templates/admin/inventory/helpers/list/ - ADMIN/themes/default/template/controllers/MODULE/helpers/list ... but Prestashop load the original file : ADMIN/themes/default/template/helpers/list/list.tpl ... Any idea ? Thanks Link to comment Share on other sites More sharing options...
be_tnt Posted February 7, 2013 Author Share Posted February 7, 2013 in Helper.pho, you can see the different folder where the system looks for template overriden: /** * Create a template from the override file, else from the base file. * * @param string $tpl_name filename * @return Template */ public function createTemplate($tpl_name) { if ($this->override_folder) { if ($this->context->controller instanceof ModuleAdminController) $override_tpl_path = $this->context->controller->getTemplatePath().$this->override_folder.$this->base_folder.$tpl_name; else if ($this->module) $override_tpl_path = _PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/_configure/'.$this->override_folder.$this->base_folder.$tpl_name; else { if (file_exists($this->context->smarty->getTemplateDir(1).DIRECTORY_SEPARATOR.$this->override_folder.$this->base_folder.$tpl_name)) $override_tpl_path = $this->context->smarty->getTemplateDir(1).DIRECTORY_SEPARATOR.$this->override_folder.$this->base_folder.$tpl_name; else if (file_exists($this->context->smarty->getTemplateDir(0).DIRECTORY_SEPARATOR.'controllers'.DIRECTORY_SEPARATOR.$this->override_folder.$this->base_folder.$tpl_name)) $override_tpl_path = $this->context->smarty->getTemplateDir(0).'controllers'.DIRECTORY_SEPARATOR.$this->override_folder.$this->base_folder.$tpl_name; } } else if ($this->module) $override_tpl_path = _PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/_configure/'.$this->base_folder.$tpl_name; if (isset($override_tpl_path) && file_exists($override_tpl_path)) { return $this->context->smarty->createTemplate($override_tpl_path, $this->context->smarty); } else return $this->context->smarty->createTemplate($this->base_folder.$tpl_name, $this->context->smarty); } In your case, the path where to store the list.tpl would be: $override_tpl_path = _PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/_configure/'.$this->override_folder.$this->base_folder.$tpl_name; hope this will help you. 1 Link to comment Share on other sites More sharing options...
Mehdib92 Posted April 24, 2013 Share Posted April 24, 2013 (edited) Hi, I'm trying to override form.tpl. I created the folders and the file for $override_tpl_path = _PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/_configure/'.$this->override_folder.$this->base_folder.$tpl_name; but I don't understand how to call this file because $this->module is empty. Thanks EDIT : It's resolved... the real path was $override_tpl_path = $this->context->controller->getTemplatePath().$this->override_folder.$this->base_folder.$tpl_name; Edited April 24, 2013 by Mehdib92 (see edit history) Link to comment Share on other sites More sharing options...
desmowow Posted July 10, 2014 Share Posted July 10, 2014 (edited) There is a way to override the form.tpl without changing the Helper.php class Place the form.tpl file in the following folder : {module_dir}/views/templates/admin/{AdminController->tpl_folder}/helpers/form/form.tpl You can find the {AdminController->tpl_folder} in AdminController.php class at row 381 $this->tpl_folder = Tools::toUnderscoreCase(substr($this->controller_name, 5)).'/'; Prestashop version 1.6.0.8 Edited July 10, 2014 by desmowow (see edit history) 3 Link to comment Share on other sites More sharing options...
karthiiiiiiiiiik Posted August 13, 2014 Share Posted August 13, 2014 (edited) Hi i have created my own module which is having a backoffice controller file which is similar to order detail page in order page, when i click on the view link , i am getting a blank page. i have placed the helpers/views/view.tpl but i am not getting anything. i have placed under mymodulename/views/templates/admin/mymodulename/helpers/views/view.tpl or in mymodulename folder after the admin folder i have to give my controller folder name. how to give {AdminController->tpl_folder} here my controller name is adminvendorder. Edited August 13, 2014 by karthiiiiiiiiiik (see edit history) Link to comment Share on other sites More sharing options...
YanK Posted October 14, 2015 Share Posted October 14, 2015 It's work for me. Thanks a lot. Put your form.tpl in :mymodule/views/templates/admin/controllername/helpers/form/form.tpl class AdminControllernameController extends ModuleAdminController { ... } Link to comment Share on other sites More sharing options...
ChDUP Posted January 19, 2016 Share Posted January 19, 2016 Hi How to do this if we don't use a controller ? I'm looking for the mailalerts module. It puts his override in views/templates/admin/_configure/helpers/form/form.tpl But it doesn't use any controller _configure Link to comment Share on other sites More sharing options...
Mehdib92 Posted January 19, 2016 Share Posted January 19, 2016 The admin template of a module use a controller too. You can override the admin module template. If you want to add other infos, you will also have to override your module. Link to comment Share on other sites More sharing options...
ChDUP Posted January 19, 2016 Share Posted January 19, 2016 I don't want to add more informations Just change the template "disposition". My module works fine with my own form, without using helperform. But I would like to use helperform, and for this, I need to override form.tpl I don't understand the path I must use for my form.tpl file. Thanks for your help Link to comment Share on other sites More sharing options...
tonagra Posted March 1, 2016 Share Posted March 1, 2016 mymodule/views/templates/admin/controllername/helpers/form/form.tplBUT!!!PrestaShop use Tools::toUnderscoreCase() for "controllername", which modifies "controllername" value.... If you have "CMSCategories" controler name, when need use 'cms_categories' folder... 1 Link to comment Share on other sites More sharing options...
ChDUP Posted July 8, 2016 Share Posted July 8, 2016 Please, can you help me ?This is my controller, with renderform functionhttp://pastebin.com/FG6URnxW I've create my own form.tpl in modules/edelweiss_revenues/views/templates/admin/revenues/helpers/form/form.tpl "revenues" is my controller name.I can display it with Tools::toUnderscoreCase(substr($this->controller_name, 5)); But form templating is still the original one, it doesn't take my override :-(What's wrong please ? Thanks Link to comment Share on other sites More sharing options...
Guest Posted July 12, 2016 Share Posted July 12, 2016 (edited) BUT!!! PrestaShop use Tools::toUnderscoreCase() for "controllername", which modifies "controllername" value.... If you have "CMSCategories" controler name, when need use 'cms_categories' folder... that means your controllername : "revenues"might be changed to _revenues, as i understood from previous explanations EDIT : it seems that you already check that, sorry I can display it with Tools::toUnderscoreCase(substr($this->controller_name, 5)); Edited July 12, 2016 by Guest (see edit history) Link to comment Share on other sites More sharing options...
ReactionCode Posted October 11, 2017 Share Posted October 11, 2017 To make it clear to everyone. This is more easy than we can thought, so forget to override classes/controllers or copy the files on admin folder For PS1.6 and above (I didn't check on PS.15) The function dedicated to fetch the template is createTemplate from Helper Class take a look for more details, or other specific situations. Basic example to override helper form.tpl, just create the file on the next folder. Override the helper form of your module: /modules/module_name/views/templates/admin/_configure/helpers/form/form.tpl Override the helper form of your module controller: /modules/module_name/views/templates/admin/controllername/helpers/form/form.tpl That's all. 1 1 Link to comment Share on other sites More sharing options...
Marik Posted January 29, 2019 Share Posted January 29, 2019 If anyone still need help with this, you have to create a new form.tpl in your module using the following structure: modules mymodule controllers MymoduleController.php mymodule.php views templates admin _customize (this folder can have other name, this depends on your prestashop version, so look in the Helper.php, in createTemplate() function to find out the path and the right name) helpers form form.tpl Check this tutorial. Link to comment Share on other sites More sharing options...
Kogkalidis Posted October 7, 2019 Share Posted October 7, 2019 On 7/10/2014 at 11:43 AM, desmowow said: There is a way to override the form.tpl without changing the Helper.php class Place the form.tpl file in the following folder : {module_dir}/views/templates/admin/{AdminController->tpl_folder}/helpers/form/form.tpl Still here in v. 1.7.6.1. Thanx man for helping in not wasting my time. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now