templates - Magento 通过代码获取电子邮件模板

标签 templates magento

我为自定义模块创建了一个电子邮件模板,将文件放在 app/locale/en_US/template/email并在我的模块配置 XML 文件中配置它。现在我想通过代码在 Controller 中检索该模板。我试过了 :

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

我错过了什么?

** 编辑 **

我找到了this代码,但行
$template_collection =  Mage::getResourceSingleton('core/email_template_collection');

返回一个空集合。我试图查看 Magento 的管理源并找到 Mage_Adminhtml_Block_System_Email_Template_Grid它也使用同一行来获取集合,显然,它适用于 Magento,但不适用于我的代码。为什么?

最佳答案

您发布的 PHP

$emailTemplate  = Mage::getModel('core/email_template')->loadByCode('custom_template');

将加载电子邮件模板 来自数据库 .具体来说,来自 core_email_template table 。您放置在文件系统上的模板是默认模板。您应该可以使用 loadDefault 加载它方法。
$emailTemplate  = Mage::getModel('core/email_template')->loadDefault('custom_template');

关于templates - Magento 通过代码获取电子邮件模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10543986/

相关文章:

c++ - 如何在 C++ operator() 中专门化调用模板?

magento - Paypal 订单未通过 Magento

magento - 如何更新 Magento 中的订单项自定义选项?

magento - 覆盖 Magento block 和模板

Magento 性能调整

c++ - 在 C++ 中从自身派生模板类

C++ 获取函数参数的字节数

c++ - 为什么模板参数失去常量性?

c++ - 为 CGAL c++ 构造模板类型

php - 访问Vagrant box中的错误日志查看 'internal server errors'