I have searched and found several posts about this topic, but none helped me. When I navigate to the controller url, I get "No template found" error. But the template is created and assigned. The url is something like this:
<mydomain>/index.php?catId=1234&fc=module&module=mymodule&controller=myfunction
This is my very simple module and folder structure:
modules/mymodule/mymodule.php
<?php if (!defined('_PS_VERSION_')) { exit; } class mymodule extends Module { public function __construct() { $this->name = 'mymodule'; $this->tab = 'front_office_features'; $this->version = '1.0.0'; $this->author = 'Tester'; $this->need_instance = 0; $this->ps_versions_compliancy = array( 'min' => '1.7.0.0', 'max' => _PS_VERSION_ ); $this->bootstrap = true; $this->controllers = array('myfunction'); parent::__construct(); $this->displayName = $this->trans('MyModule', array(), 'Modules.Mainmenu.Admin'); $this->description = $this->trans('My first simple module', array(), 'Modules.Mainmenu.Admin'); $this->confirmUninstall = $this->l('Do you want to uninstall?'); } public function install() { if (version_compare(_PS_VERSION_,'1.5','>=')) { if (Shop::isFeatureActive()) Shop::setContext(Shop::CONTEXT_ALL); } return parent::install(); } public function uninstall() { return parent::uninstall(); } public function getContents() { echo "Step 1"; } public function hookDisplayHome($params) { $this->context->smarty->assign( 'moduleLink', $this->context->link->getModuleLink( $this->name, 'myfunction', array('catId' => 1337 ) ) ); return $this->display(__FILE__, 'views/templates/hook/testfrontctrl.tpl'); } }
modules/mymodule/controllers/front/myfunction.php
<?php class mymodulemyfunctionModuleFrontController extends ModuleFrontController { public function __construct() { parent::__construct(); } public function init() { $this->page_name = 'myfunction'; $this->display_column_left = false; $this->display_column_right = false; parent::init(); } public function initContent() { parent::initContent(); // Do some process echo 'RESULT OK : ' . Tools::getValue('catId'); $this->setTemplate(_PS_MODULE_DIR_.'mymodule/views/templates/front/myfunction.tpl'); } }
modules/mymodule/views/templates/front/myfunction.tpl
modules/mymodule/views/templates/hook/testfrontctrl.tpl
(both same content)
<h2>Hello world</h2>