Jump to content

[RESOLVED] Override the helpers form.tpl


be_tnt

Recommended Posts

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 by be_tnt (see edit history)
Link to comment
Share on other sites

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

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

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).

  • Like 1
Link to comment
Share on other sites

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

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.

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

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 by Mehdib92 (see edit history)
Link to comment
Share on other sites

  • 1 year later...
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 by desmowow (see edit history)
  • Like 3
Link to comment
Share on other sites

  • 1 month later...

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 by karthiiiiiiiiiik (see edit history)
Link to comment
Share on other sites

  • 1 year later...
  • 3 months later...

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

  • 1 month later...

mymodule/views/templates/admin/controllername/helpers/form/form.tpl


BUT!!!

PrestaShop use Tools::toUnderscoreCase() for "controllername", which modifies "controllername" value.... If you have "CMSCategories" controler name, when need use 'cms_categories' folder...

  • Like 1
Link to comment
Share on other sites

  • 4 months later...

Please, can you help me ?

This is my controller, with renderform function
http://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

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 by Guest (see edit history)
Link to comment
Share on other sites

  • 1 year later...
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.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 1 year later...

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

  • 8 months later...
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

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
×
×
  • Create New...