Rycka Posted January 28, 2023 Share Posted January 28, 2023 Hello, I'm learning how to create PrestaShop module, by it's Documentation here: https://devdocs.prestashop-project.org/1.7/modules/creation/displaying-content-in-front-office/ I saw dozens of posts like this, and there is no SOLUTION??? Does this mean PS Documentation is lying?! My Controller Front-end page is not embedding with main theme, which parent::initContent() should do, but it's doing NOTHING... I'm just seeing 'This is my view' of my display.tpl in white screen, no main theme content. Debug mode shows no errors, and yes I deleted my cache, set to force Template Compilation, tried dozens of "SOLUTIONS", and nothing... Here's my code: modules\manomodulis\manomodulis.php <?php /** * Copyright since 2007 PrestaShop SA and Contributors * PrestaShop is an International Registered Trademark & Property of PrestaShop SA * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License version 3.0 * that is bundled with this package in the file LICENSE.md. * It is also available through the world-wide-web at this URL: * https://opensource.org/licenses/AFL-3.0 * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * @author PrestaShop SA and Contributors <[email protected]> * @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 */ if (!defined('_PS_VERSION_')) { exit; } class ManoModulis extends Module { public function __construct() { $this->name = 'manomodulis'; $this->tab = 'front_office_features'; $this->version = '1.0'; $this->author = 'Rytis Plečkauskas'; $this->need_instance = 0; $this->ps_versions_compliancy = [ 'min' => '1.6', 'max' => _PS_VERSION_ ]; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Mano Modulis'); $this->description = $this->l('Mano pirmas PrestaShop modulis.'); $this->confirmUninstall = $this->l('Ar tikrai nori ištrinti šitai?!?'); if (!Configuration::get('MANOMODULIS_ARGERAS')) { $this->warning = $this->l('No name provided'); } } public function install() { if (Shop::isFeatureActive()) { Shop::setContext(Shop::CONTEXT_ALL); } return (parent::install() && $this->registerHook('displayLeftColumn') && $this->registerHook('displayHeader') && Configuration::updateValue('MANOMODULIS_ARGERAS', 'Taip') ); } public function uninstall() { return (parent::uninstall() && Configuration::deleteByName('MANOMODULIS_ARGERAS') ); } /** * This method handles the module's configuration page * @return string The page's HTML content */ public function getContent() { $output = ''; // this part is executed only when the form is submitted if (Tools::isSubmit('submit' . $this->name)) { // retrieve the value set by the user $configValue = (string) Tools::getValue('MANOMODULIS_ARGERAS'); // check that the value is valid if ( empty($configValue) || !Validate::isGenericName($configValue) || !in_array($configValue, ['Taip', 'Ne']) ) { // invalid value, show an error $output = $this->displayError($this->l('Bloga reikšmė. Tik Taip arba Ne')); } else { // value is ok, update it and display a confirmation message Configuration::updateValue('MANOMODULIS_ARGERAS', $configValue); $output = $this->displayConfirmation($this->l('Atnaujinta!')); } } // display any message, then the form return $output . $this->displayForm(); } /** * Builds the configuration form * @return string HTML code */ public function displayForm() { // Init Fields form array $form = [ 'form' => [ 'legend' => [ 'title' => $this->l('Nustatymai'), ], 'input' => [ [ 'type' => 'text', 'label' => $this->l('Ar geras Mano Modulis'), 'name' => 'MANOMODULIS_ARGERAS', 'size' => 4, 'required' => true, ], ], 'submit' => [ 'title' => $this->l('IŠSAUGOTI'), 'class' => 'btn btn-default pull-right', ], ], ]; $helper = new HelperForm(); // Module, token and currentIndex $helper->table = $this->table; $helper->name_controller = $this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->currentIndex = AdminController::$currentIndex . '&' . http_build_query(['configure' => $this->name]); $helper->submit_action = 'submit' . $this->name; // Default language $helper->default_form_language = (int) Configuration::get('PS_LANG_DEFAULT'); // Load current value into the form $helper->fields_value['MANOMODULIS_ARGERAS'] = Tools::getValue('MANOMODULIS_ARGERAS', Configuration::get('MANOMODULIS_ARGERAS')); return $helper->generateForm([$form]); } public function hookDisplayLeftColumn($params) { $this->context->smarty->assign([ 'my_module_name' => Configuration::get('MANOMODULIS_ARGERAS'), 'my_module_link' => $this->context->link->getModuleLink('manomodulis', 'display', [], null, null, null, true) ]); return $this->display(__FILE__, 'manomodulis.tpl'); } public function hookDisplayRightColumn($params) { return $this->hookDisplayLeftColumn($params); } public function hookActionFrontControllerSetMedia() { $this->context->controller->registerStylesheet( 'manomodulis-style', $this->_path . 'views/css/manomodulis.css', [ 'media' => 'all', 'priority' => 1000, ] ); $this->context->controller->registerJavascript( 'manomodulis-javascript', $this->_path . 'views/js/manomodulis.js', [ 'position' => 'bottom', 'priority' => 1000, ] ); } } modules\manomodulis\controllers\front\display.php <?php class manomodulisdisplayModuleFrontController extends ModuleFrontController { public function initContent() { parent::initContent(); $this->setTemplate('module:manomodulis/views/templates/front/display.tpl'); } } modules\manomodulis\views\templates\front\display.tpl This is my view modules\manomodulis\views\templates\hook\manomodulis.tpl <!-- Block manomodulis --> <div id="manomodulis_block_home" class="block"> <h4>{l s='Welcome!' mod='manomodulis'}</h4> <div class="block_content"> <p>Hello, {if isset($my_module_name) && $my_module_name} {$my_module_name} {else} World {/if} ! </p> <ul> <li><a href="{$my_module_link}" title="Click this link">Click me!</a></li> </ul> </div> </div> <!-- /Block manomodulis --> I someone knows what's bad, please answer. Hundreds Thanks! manomodulis.zip Link to comment Share on other sites More sharing options...
endriu107 Posted January 28, 2023 Share Posted January 28, 2023 Try add to __construct() this line: $this->controllers = array('display'); so it should looks like: public function __construct() { $this->name = 'manomodulis'; $this->tab = 'front_office_features'; $this->version = '1.0'; $this->author = 'Rytis Plečkauskas'; $this->need_instance = 0; $this->controllers = array('display'); $this->ps_versions_compliancy = [ 'min' => '1.6', 'max' => _PS_VERSION_ ]; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Mano Modulis'); $this->description = $this->l('Mano pirmas PrestaShop modulis.'); $this->confirmUninstall = $this->l('Ar tikrai nori ištrinti šitai?!?'); if (!Configuration::get('MANOMODULIS_ARGERAS')) { $this->warning = $this->l('No name provided'); } } Link to comment Share on other sites More sharing options...
Rycka Posted January 28, 2023 Author Share Posted January 28, 2023 Hi, endriu107, thanks for your response, but however it's still not working. Link to comment Share on other sites More sharing options...
endriu107 Posted January 28, 2023 Share Posted January 28, 2023 There is more errors like: class manomodulisdisplayModuleFrontController extends ModuleFrontController should be: class manomodulisDisplayModuleFrontController extends ModuleFrontController Link to comment Share on other sites More sharing options...
endriu107 Posted January 28, 2023 Share Posted January 28, 2023 Inside file modules\manomodulis\views\templates\front\display.tpl content should be like this: {extends file='page.tpl'} {block name='page_content'} THERE CONTENT TO DISPLAY {/block} Link to comment Share on other sites More sharing options...
Rycka Posted January 28, 2023 Author Share Posted January 28, 2023 Thank you endriu107, that worked. I tried these solutions before, but I didn't had this line: $this->controllers = array('display'); Looks like everything together got it working. Thanks again. 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