I need a dynamic variable to be called in email header and footer based off of the name of the main email template.

I achieved this by adding my variable directly in the setTemplateParams()function which is called by the send() function in app/code/core/Mage/Core/Model/Email/Template/Mailer.php.

$template =
       $templateName = $template->getTemplateCode();

    $templateParams['template_name'] = str_replace(' ', '_',$templateName);

This worked fine for my order confirmation email where I was able to call this variable with
{{var template_name}} However when I tested a stock alert email I discovered that it does not call this send() function in app/code/core/Mage/Core/Model/Email/Template/Mailer.php instead it has it's own send() function in app/code/core/Mage/ProductAlert/Model/Email.php.

Is there any one spot where I would be able to add this variable to all email templates.(I need somewhere that i have access to the current templates Id to get the template name, or anywhere that I would have direct access to the template name).

1 Answer 1


If you look at the app/code/core/Mage/ProductAlert/Model/Email.php::send() method and the app/code/core/Mage/Core/Model/Email/Template/Mailer.php::send method, you will see that both finally use the Mage_Core_Model_Email_Template::sendTransactional method.

So, I would suggest to rewrite the Mage_Core_Model_Email_Template model in order to have your own sendTransactional method.

In this rewritten model, you can use the $templateId param to get the template name and add it to the $vars param.

For example, with the same logic you used :

public function sendTransactional($templateId, $sender, $email, $name, $vars=array(), $storeId=null){

    $template = Mage::getModel('adminhtml/email_template')->load($templateId);
    $templateName = $template->getTemplateCode();
    $vars['template_name'] = str_replace(' ', '_',$templateName);
    return parent::sendTransactional($templateId, $sender, $email, $name, $vars, $storeId);


This way, this should work for every transactionnal emails.

  • 1
    Julien Loizelet you preempted me with your answer. I was in middle of trying out overwriting sendTransaction. It seems to work perfectly. However for templates using default there's no name so I'm just using the id to see what type of template is being used. That works for my purposes. Oct 25, 2018 at 16:32

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.