dylanwijnen1 Posted May 9, 2017 Share Posted May 9, 2017 (edited) Hey there, I'm developing a module and I am trying to use a custom template as its done in the product section from prestashop. Looking at the code it shows the following code to use a custom template for different tabs: this controller extends AdminController if (method_exists($this, 'initForm'.$this->tab_display)) $this->tpl_form = strtolower($this->tab_display).'.tpl'; $this->tpl_form_vars['custom_form'] = $data->fetch(); My code is the following placed inside the initContent method And I am extending ModuleAdminController public function initContent() { if ($this->display == 'edit' || $this->display == 'add') { $this->fields_form = array(); $this->tpl_form = "my_form.tpl"; $this->initMyForm(); } parent::initContent(); } public function initMyForm() { if (!$this->default_form_language) $this->getLanguages(); $data = $this->context->smarty->createTemplate($this->tpl_form); //echo $this->getTemplatePath().$this->override_folder.$this->tpl_form; //echo "<pre>".print_r($data, true)."</pre>"; //exit; $data->assign('languages', $this->_languages); $data->assign('default_form_language', $this->default_form_language); $data->assign('ad', dirname($_SERVER['PHP_SELF'])); $data->assign('id_lang', $this->context->language->id); $data->assign('token', $this->token); $data->assign($this->tpl_form_vars); $data->assign('link', $this->context->link); //When fetching throws the following : Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file $this->tpl_form_vars['custom_form'] = $data->fetch(); } I've double checked the path to the template which ModuleAdminController uses to create the template it is correct. Yet when trying to display with $data->display(); it throws the exception described in the code above. I'd rather not use the default $fields_form variable due to custom functionality I want in the backoffice. Any help is appreciated, thanks in advance. I'm developing a module and I am trying to use a custom template as its done in the product section from prestashop. Looking at the code it shows the following code to use a custom template for different tabs: this controller extends AdminController if (method_exists($this, 'initForm'.$this->tab_display)) $this->tpl_form = strtolower($this->tab_display).'.tpl'; $this->tpl_form_vars['custom_form'] = $data->fetch(); My code is the following placed inside the initContent method And I am extending ModuleAdminController public function initContent() { if ($this->display == 'edit' || $this->display == 'add') { $this->fields_form = array(); $this->tpl_form = "my_form.tpl"; $this->initMyForm(); } parent::initContent(); } public function initMyForm() { if (!$this->default_form_language) $this->getLanguages(); $data = $this->context->smarty->createTemplate($this->tpl_form); //echo $this->getTemplatePath().$this->override_folder.$this->tpl_form; //echo "<pre>".print_r($data, true)."</pre>"; //exit; $data->assign('languages', $this->_languages); $data->assign('default_form_language', $this->default_form_language); $data->assign('ad', dirname($_SERVER['PHP_SELF'])); $data->assign('id_lang', $this->context->language->id); $data->assign('token', $this->token); $data->assign($this->tpl_form_vars); $data->assign('link', $this->context->link); //When fetching throws the following : Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file $this->tpl_form_vars['custom_form'] = $data->fetch(); } I've double checked the path to the template which ModuleAdminController uses to create the template it is correct. Yet when trying to display with $data->display(); it throws the exception described in the code above. I'd rather not use the default $fields_form variable due to custom functionality I want in the backoffice. Any help is appreciated, thanks in advance. *EDIT* After looking around I found the directory isn't added to smarty and prestashop ModuleAdminController doesn't do it itself. Fixed by adding this code $this->context->smarty->addTemplateDir($this->getTemplatePath().$this->override_folder); Edited May 9, 2017 by dylanwijnen1 (see edit history) 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