briast Posted June 25, 2020 Share Posted June 25, 2020 (edited) 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> Edited June 25, 2020 by briast (see edit history) Link to comment Share on other sites More sharing options...
Razi Posted June 25, 2020 Share Posted June 25, 2020 Kindly check you have enable friendly URls ? Link to comment Share on other sites More sharing options...
briast Posted June 25, 2020 Author Share Posted June 25, 2020 Yes. It's enabled. I don't know why it throws this exception. No template found for ../public_html/modules/mymodule/views/templates/front/myfunction.tpl when this tpl file exists and It is in this folder. Link to comment Share on other sites More sharing options...
Razi Posted June 25, 2020 Share Posted June 25, 2020 you can make the controller url using this method $url = $this->context->link->getModuleLink( 'module_name', 'controller', array(), null, null, Configuration::get('PS_SHOP_DEFAULT') ); If you have no perameters then use $url = $this->context->link->getModuleLink( 'module_name', 'controllername' ); and your url look like this http://domain_name.com/module/module_name/controller_name Link to comment Share on other sites More sharing options...
Razi Posted June 25, 2020 Share Posted June 25, 2020 In controller Also need to fix the return return $this->setTemplate('tpl_name.tpl'); and file location must be there /modules/module_name/views/templates/front/tpl_name.tpl Link to comment Share on other sites More sharing options...
briast Posted June 25, 2020 Author Share Posted June 25, 2020 (edited) 2 hours ago, Razi said: In controller Also need to fix the return return $this->setTemplate('tpl_name.tpl'); Before posting my question, I've tried all combinations I have found in internet. With this, I get the same error. I need my own url with parameters. Edited June 25, 2020 by briast (see edit history) Link to comment Share on other sites More sharing options...
briast Posted June 29, 2020 Author Share Posted June 29, 2020 On 6/25/2020 at 12:44 PM, Razi said: Kindly check you have enable friendly URls ? I've tried but the same error. Link to comment Share on other sites More sharing options...
Guest Posted June 29, 2020 Share Posted June 29, 2020 (edited) $this->setTemplate('module:mymodule/views/templates/front/myfunction.tpl'); Edited June 29, 2020 by Guest (see edit history) Link to comment Share on other sites More sharing options...
briast Posted June 29, 2020 Author Share Posted June 29, 2020 I can't believe it. It works like a charm. The error is gone. Thanks for your help. Link to comment Share on other sites More sharing options...
Guest Posted June 29, 2020 Share Posted June 29, 2020 I gladly helped. You can give a like by clicking on the gray heart below the posts. 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