Jump to content

No template found module error


Recommended Posts

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 by briast (see edit history)
Link to comment
Share on other sites

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

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

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 by briast (see edit history)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...