I want pass custom template variables to footer template.

In which file i need make changes to pass my customer template variables to footer template.


1 Answer 1


You need to create an event for email templates.

First of all, create an event with the name email_order_set_template_vars_before

<?xml version="1.0" encoding="utf-8"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="email_order_set_template_vars_before">
    <observer name="custom_email_variable"
              instance="Vendor\ModuleName\Observer\CustomVar" />

Then, we make the observer class in which we put the code:

namespace Vendor\ModuleName\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Sales\Model\Order;

class CustomVar implements ObserverInterface
     * Execute method
     * @param Observer $observer
     * @return void
    public function execute(Observer $observer)
        $transportObject = $observer->getEvent()->getData('transportObject');

        $transportObject['custom_variable'] = $this->customMethod();

     * Custom method
     * @return string
    protected function customMethod(): string
        return 'Test custom var';

Now, you will be able to call the custom_variable variable and you will receive the message from the return.

  • HI @Bogdan Pisica, is it work for all emails or only for order emails. I assume "email_order_set_template_vars_before" event works for order emails only.
    – Mani
    Commented Oct 14, 2022 at 5:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.