Pass variable to all email templates

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Pass variable to all email templates

Post by MikaelNazarenko » 29 Mar 2022, 16:09

Hi Aimeos!

Is it possible to pass variable to all email templates? I tried to add decorator but it doesn't work..

Here is decorator:

Code: Select all

namespace Aimeos\Controller\Jobs\Common\Decorator;

class CustomDecorator extends Base
{

    protected $partialHelper;

    public function __construct(\Aimeos\Controller\Jobs\Iface $controller, \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\Bootstrap $aimeos)
    {
        parent::__construct($controller, $context, $aimeos);

        $view = $context->getView();
        $view->settings = 324234;

        $view->addHelper('partial', $this->getPartialHelper($view));

    }

    protected function getPartialHelper(\Aimeos\MW\View\Iface $view)
    {
        if(!$this->partialHelper) {
            $this->partialHelper = new \Aimeos\Controller\Jobs\Common\Helper\Partial\Partial($view);
        }
        return $this->partialHelper;
    }
}
Partial:

Code: Select all

class Partial extends \Aimeos\MW\View\Helper\Partial\Standard
{
    public function transform(string $file, array $params = []): string
    {
        $view = $this->getView();

        $params['settings'] = 234234342;

        dd(76567);

        return parent::transform($file, $params);
    }
}

but settings variable not accessable in email templates (

User avatar
aimeos
Administrator
Posts: 7895
Joined: 01 Jan 1970, 00:00

Re: Pass variable to all email templates

Post by aimeos » 30 Mar 2022, 13:54

This doesn't work because the emails are not generated using partials which are only a way to include the output from another template.

You can create a HTML client decorator and implement the addData() method which then adds your settings to the passed view like described here: https://aimeos.org/docs/latest/frontend ... omponents/


The configuration to apply the decorator to ALL HTML clients (not only for the email ones) would be:

Code: Select all

client/html/common/decorators/default = ['Mydecorator']
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply