Jump to content

Inject variables into header.tpl for delivery-slip


Recommended Posts

Hey there,

Using prestashop 8. 

I wrote a module that assigns data for the delivery-slip pdf. 
Something like this:

    public function hookDisplayPDFDeliverySlip($hookArgs)
    {
        $hookArgs['object']->my_param = "hello world";
    }



But now I would also need some params in the header.tpl. 

What have I tried:
   

 public function hookDisplayPDFDeliverySlip($hookArgs)
    {
        $this->context->smarty->assign([
            'test1234' => 'hello world test1234',
        ]);
    }



But this `test1234` variable is not available in `header.tpl` nor in `delivery-slip.tpl`.

What other solutions i have thought about:
- Override the `HTMLTemplate.php` file to add custom logic. I would rather not like to do that because updates will become hard
- Create my own pdf generator like described here: https://devdocs.prestashop-project.org/8/modules/concepts/pdf/#code-example. Would be very overkill and I would need to basically copy the existing delivery slip generator and just modify slightly. Again it would be hard to update.

What's the recommended approach for this problem? 

Thanks! 

Link to comment
Share on other sites

Finally found a solution. I realised that smarty is also passed as an argument so you can do this:

 

    public function hookDisplayPDFDeliverySlip($hookArgs)
    {
        $smarty = $hookArgs['smarty'];
        $smarty->assign('test1234', "hello world");
	}


this variable will than be available both in `delivery-slip.pdf` and `header.tpl`

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