Fruitcake_Gary Posted March 1 Share Posted March 1 Cześć Mam problem z renderowaniem zawartości w moim customowym module. Całość odbywa się w panelu admina. O ile sam moduł się wgrywa i pojawia się nowa zakładka, o tyle zmienne wydają się nie być przekazywane do widoku. Struktura modułu: modules/imagemanager/imagemanager.php <?php if (!defined('_PS_VERSION_')) { exit; } class ImageManager extends Module { public function __construct() { $this->name = 'imagemanager'; $this->tab = 'administration'; $this->version = '1.0.0'; $this->author = 'Test Test'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Image Manager'); $this->description = $this->l('Simple Image Manager module.'); } public function install() { return parent::install() && $this->registerTab(); } public function uninstall() { return parent::uninstall() && $this->unregisterTab(); } private function registerTab() { $tab = new Tab(); $tab->class_name = 'AdminImageManager'; $tab->id_parent = (int)Tab::getIdFromClassName('AdminParentModulesSf'); $tab->module = $this->name; $tab->name = []; foreach (Language::getLanguages() as $lang) { $tab->name[$lang['id_lang']] = 'Image Manager'; } return $tab->add(); } private function unregisterTab() { $id_tab = (int)Tab::getIdFromClassName('AdminImageManager'); if ($id_tab) { $tab = new Tab($id_tab); return $tab->delete(); } return true; } } modules/imagemanager/controllers/admin/AdminImageManagerController.php <?php class AdminImageManagerController extends ModuleAdminController { public function __construct() { parent::__construct(); $this->bootstrap = true; } public function initContent() { parent::initContent(); $this->context->smarty->assign([ 'message' => 'test', 'current_date' => date('Y-m-d H:i:s') ]); $templatePath = _PS_MODULE_DIR_ . 'imagemanager/views/templates/admin/imagemanager.tpl'; if (!file_exists($templatePath)) { die('<h1 style="color:red;">BŁĄD: Plik szablonu nie istnieje: ' . $templatePath . '</h1>'); } return $this->setTemplate('imagemanager.tpl'); } } modules/imagemanager/views/templates/admin/imagemanager.tpl {extends file="helpers/view/view.tpl"} {block name="content"} <div class="panel"> <h2>{l s='ImageMANAGER' mod='imagemanager'}</h2> <p>This is content from a .tpl file.</p> </div> {/block} Tak się to objawia: Kiedy $this->setTemplate('imagemanager.tpl'); zamienię na echo '<h1>TEST TEST</h1>'; inny przykład testu echo '<pre>'; print_r($this->context->smarty->getTemplateVars()); echo '</pre>'; exit; [current_tab_level] => 2 [install_dir_exists] => [pic_dir] => /upload/ [controller_name] => AdminImageManager [currentIndex] => index.php?controller=AdminImageManager [bootstrap] => 1 [default_language] => 1 [content] => [message] => test [current_date] => 2025-02-28 22:20:29 zamiana na: $this->setTemplate('module:imagemanager/views/templates/admin/imagemanager.tpl'); dostaję taki błąd Nie wiem w czym jest problem. Kiedyś pisałem inne moduły w podobnym stylu i ten problem się nie pojawiał. Środowisko: Docker - windows 10 wersja Presta: 8.2.0 Link to comment Share on other sites More sharing options...
Fruitcake_Gary Posted March 4 Author Share Posted March 4 Mały update: imagemaneger/controllers/admin/AdminImageManagerController.php <?php class AdminImageManagerController extends ModuleAdminController { public function __construct() { parent::__construct(); $this->bootstrap = true; } public function initContent() { parent::initContent(); $this->content .= '<h1 style="color: red;">TEST</h1>'; $templatePath = _PS_MODULE_DIR_ . 'imagemanager/views/templates/admin/imagemanager.tpl'; if (file_exists($templatePath)) { $this->content .= $this->context->smarty->fetch($templatePath); } else { $this->content .= '<p style="color: red;">BŁĄD: Plik `.tpl` nie istnieje</p>'; } } } Sprawia, ze strona się ładuje, ale nic nie wyświetla: 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