Jump to content

Missing '$template' parameter when rendering template in hookActionValidateOrder


Recommended Posts

I'm using Prestashop 1.7.6.4 to develop a payment module. 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

in smarty_internal_templatebase.php line 177
at Smarty_Internal_TemplateBase->_execute(null, null, 'layouts/layout-full-width.tpl', null, 0)
in smarty_internal_templatebase.php line 116
at Smarty_Internal_TemplateBase->fetch(null, null, 'layouts/layout-full-width.tpl', null, false, true, false)
in SmartyDev.php line 40
at SmartyDev->fetch(null, null, 'layouts/layout-full-width.tpl')
in FrontController.php line 683
at FrontControllerCore->smartyOutputContent(null)
in FrontController.php line 667
at FrontControllerCore->display()
in Controller.php line 312
at ControllerCore->run()
in Dispatcher.php line 515
at DispatcherCore->dispatch()
in index.php line 74

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

The template contains the following code:

{if $module == "myModule"}
    <script>
        $(document).ready(function() {
           alert('test');
        });

        alert('test');
    </script>
{/if}

My folder structure is like so:

    myModuleName
      views
        templates
          hook
            displayStatusOrder.tpl

I think it's because I'm trying to render it in this specific hook. It seems that for other hooks rendering templates works just fine.

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

I'm clearly missing something obvious. Any help is appreciated.

Edited by junkypic (see edit history)
Link to comment
Share on other sites

1 hour ago, idnovate.com said:

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.

Indeed that was the problem. 

For my case specifically I had to reroute to a controller and display a tpl with some javascript in it.

  • Like 1
Link to comment
Share on other sites

  • 10 months later...
  • 1 year later...

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...