Templates Magento通过代码获取电子邮件模板
我已经为自定义模块创建了一个电子邮件模板,将该文件放置在Templates Magento通过代码获取电子邮件模板,templates,magento,Templates,Magento,我已经为自定义模块创建了一个电子邮件模板,将该文件放置在app/locale/en_US/template/email中,并在我的模块配置XML文件中对其进行了配置。现在我想通过代码在控制器中检索该模板。我试过: $emailTemplate = Mage::getModel('core/email_template')->loadByCode('custom_template'); 但它返回一个NULL电子邮件模板。我的模块电子邮件模板配置为: <global>
app/locale/en_US/template/email
中,并在我的模块配置XML文件中对其进行了配置。现在我想通过代码在控制器中检索该模板。我试过:
$emailTemplate = Mage::getModel('core/email_template')->loadByCode('custom_template');
但它返回一个NULL
电子邮件模板。我的模块电子邮件模板配置为:
<global>
<template>
<email>
<custom_template>
<label>Some custom email template</label>
<file>custom_template.html</file>
<type>html</type>
</custom_template>
</email>
</template>
</global>
返回一个空集合。我试图查看Magento的管理源代码,找到了Mage\u Adminhtml\u Block\u System\u Email\u Template\u Grid
,它也使用同一行来获取集合,显然它对Magento有效,但对我的代码无效。为什么?你发布的PHP
$emailTemplate = Mage::getModel('core/email_template')->loadByCode('custom_template');
将从数据库加载电子邮件模板。具体来说,从core\u email\u模板
表。您在文件系统上放置的模板是默认模板。您应该能够使用loadDefault
方法加载它
$emailTemplate = Mage::getModel('core/email_template')->loadDefault('custom_template');
如果有人正在寻找如何基于现有的Magento电子邮件模板发送Magento电子邮件的完整示例代码,那么以下代码可以很好地工作。它不需要任何XML配置
// This is the name that you gave to the template in System -> Transactional Emails
$emailTemplate = Mage::getModel('core/email_template')->loadByCode('My Custom Email Template');
// These variables can be used in the template file by doing {{ var some_custom_variable }}
$emailTemplateVariables = array(
'some_custom_variable' => 'Hello World'
);
$processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
$emailTemplate->setSenderName('Joe Bloggs');
$emailTemplate->setSenderEmail('test@test.com');
$emailTemplate->setTemplateSubject("Here is your subject");
$emailTemplate->send('recipient@test.com', 'Joanna Bloggs', $emailTemplateVariables);
// This is the name that you gave to the template in System -> Transactional Emails
$emailTemplate = Mage::getModel('core/email_template')->loadByCode('My Custom Email Template');
// These variables can be used in the template file by doing {{ var some_custom_variable }}
$emailTemplateVariables = array(
'some_custom_variable' => 'Hello World'
);
$processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
$emailTemplate->setSenderName('Joe Bloggs');
$emailTemplate->setSenderEmail('test@test.com');
$emailTemplate->setTemplateSubject("Here is your subject");
$emailTemplate->send('recipient@test.com', 'Joanna Bloggs', $emailTemplateVariables);