Search code examples
phpprestashopprestashop-1.7

Missing $template parameter in prestashop 1.7.6, when rendered from hook


I'm using Prestashop 1.7.6.4. I want to render a template in a hook. I'm doing that via the following code:

class MyModuleName extends PaymentModule
{

    public function hookActionValidateOrder($params)
    {
        /**
         * Verify if this module is enabled
         */
        if (!$this->active) {
            return;
        }

        if (Configuration::get('inline')) {
            $this->context->smarty->assign([
                'module' => $order->module
            ]);

            return $this->display(__FILE__,
                'views/templates/hook/displayStatusOrder.tpl');

        }
        // more code goes here
    }

}

Do note that I've also tried with

return $this->fetch('module:myModule/views/templates/hook/displayStatusOrder.tpl');

results are the same.

However I'm getting the following error:

(1/1) SmartyException
0():Missing '$template' parameter

I'm absolutely sure that my template exists. And it has the correct name.

My folder structure is like so:

myModuleName
  views
    templates
      hook
        displayStatusOrder.tpl

I've tried deleting the cache, reinstalling the module, etc etc.

I'm clearly missing something obvious.


Solution

  • hookActionValidateOrder is an action hook, not a display hook, so you can not display a template.

    You need to check in your template where you want to display your code which hooks are available.