Reputation: 8282
I'm working on a prestashop
custom module development, my idea is to create a custom export module, I'm able to install the module and add the menu under catalog menu. the only issue is while installing the tpl
files not copying to the admin template folder ?
Should we copy these view with copy method inside install section of module ?
in my controller I'm trying to load the tpl file from
public function initContent() {
parent::initContent();
$smarty = $this->context->smarty;
$smarty->assign('test', 'test1');
$this->setTemplate('wwmexport/wwmexport.tpl');
}
This path file is not exist after module installation $this->setTemplate('wwmexport/wwmexport.tpl');
when I create it manually everything works fine.
I need to know is there any option to load the tpl from my module path something like below.
return $this->display(_PS_MODULE_DIR_ . 'wwmexport/views/templates/admin/wwmexport.tpl');
but that not working :(
My module structure is as follows.
wwmexport
controllers
admin
Adminwwmcontroller.php
views
templates
admin
wwmexport.tpl
wwmexport.php
controller file have
class AdminWwmExportController extends AdminController {
protected $module;
public function __construct() {
parent::__construct();
}
public function display() {
parent::display();
}
public function initContent() {
if (Tools::getValue('method') != "") {
$method = Tools::getValue('method');
$this->$method();
}
parent::initContent();
/*$smarty = $this->context->smarty;
$smarty->assign(array('test', 'test1'));*/
//$this->setTemplate('wwmexport.tpl');
global $smarty;
$smarty->display(_PS_MODULE_DIR_ . 'wwmexport/views/templates/admin/wwmexport.tpl');
}
}
my module file wwmexport.php as follows.
class WwmExport extends Module {
public function __construct() {
$this->name = 'wwmexport';
$this->tab = 'export';
$this->version = '1.0.0';
$this->author = 'Jobin Jose';
$this->need_instance = 0;
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Export');
$this->description = $this->l('Custom Export Features for Products');
$this->confirmUninstall = $this->l('Are you sure you would like to uninstall?');
}
public function install($delete_params = true) {
if (!parent::install()
/*|| !copy(_PS_MODULE_DIR_ . 'wwmexport/views/templates/admin/wwmexport.tpl', _PS_ADMIN_DIR_ . '/themes/default/template/wwmexport.tpl')*/
|| !$this->installModuleTab('AdminWwmExport', array(1 => 'Product Export'), 9)
) {
return false;
}
return true;
}
public function uninstall() {
if (!parent::uninstall()
|| !$this->uninstallModuleTab('AdminWwmExport')) {
return false;
}
return true;
}
private function installModuleTab($tabClass, $tabName, $idTabParent) {
$tab = new Tab();
$tab->name = $tabName;
$tab->class_name = $tabClass;
$tab->module = $this->name;
$tab->id_parent = $idTabParent;
if (!$tab->save()) {
return false;
}
return true;
}
private function uninstallModuleTab($tabClass) {
$idTab = Tab::getIdFromClassName($tabClass);
if ($idTab != 0) {
$tab = new Tab($idTab);
$tab->delete();
return true;
}
return false;
}
}
Solved
rewrite the initContent()
as follows.
public function initContent() {
parent::initContent();
$smarty = $this->context->smarty;
$content = $smarty->fetch(_PS_MODULE_DIR_ . 'wwmexport/views/templates/admin/wwmexport.tpl');
$this->context->smarty->assign(array('content' => $this->content . $content));
}
Upvotes: 1
Views: 3259
Reputation: 93
so it works for me
$this->display(__FILE__ , 'views/templates/admin/wwmexport.tpl');
Upvotes: 1