English 中文(简体)
Magento通过密码获得电子邮件模板
原标题:Magento get email template by code

我为海关模块建立了电子邮件模板,将文件放在<编码>app/ locale/en_US/template/email,并在我的模块XML文档中加以配置。 现在,我想通过密码在控制器中检索这一模板。 我已尝试:

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

但它退回了<代码>NUL电子邮箱模板。 我的模块电子邮件模板集:

<global>
    <template>
        <email>
            <custom_template>
                <label>Some custom email template</label>
                <file>custom_template.html</file>
                <type>html</type>
            </custom_template>
        </email>
    </template>
</global>

我失踪了什么?

** 本文件迟交。

I have found this 代码,但行文

$template_collection =  Mage::getResourceSingleton( core/email_template_collection );

回收的只是空洞。 我试图研究Magento的行政管理来源,并发现。 Mage_Adminhtml_Block_System_Email_Template_Grid which also use the same line to have a Collection and, 显然, it work for Magento, but not with my Code. 为什么?

最佳回答

The PHP you posted

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

将从数据库中装载一个电子邮件模板。 具体来说,从<代码>核心_email_template表。 存档系统中的模板是缺省模板。 您应当能够使用<代码>载荷Default方法装载。

$emailTemplate  = Mage::getModel( core/email_template )->loadDefault( custom_template );
问题回答

If anyone is looking for full sample code of how to send a Magento email based on an existing Magento email template, the following works well. It does not require any XML config.

// 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( [email protected] );
$emailTemplate->setTemplateSubject("Here is your subject");

$emailTemplate->send( [email protected] ,  Joanna Bloggs , $emailTemplateVariables);




相关问题
Check session from a view in CodeIgniter

What is the best way to check session from a view in CodeIgniter, it shows no way in their user guide, otherwise I will have to make two views on everything, which is kinda weird...still a newbie to ...

How to create a submit button template in Oracle APEX?

I m trying to create a template for a button in Oracle APEX but I don t seem to have access to the appropriate substitution strings to make it work. For non-templated buttons APEX seems to insert a ...

list of controls with templates in silverlight

Does anyone know where to find a list of controls that you can set the template on in Silverlight? I ve wasted several hours now trying to create control templates only to find that the control doesn ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Load ruby on rails template from database

I wonder if there is a way for me to store ruby on rails view files into database store and have that fetched directly from there. The reason is I want to create a CMS with all the user data stored in ...

Templated HTML Editor

I m looking for a HTML editor that kinda supports templated editing or live snippets or something like that. Background: I m working on a website for a friend. As there are no specifications what the ...

Dreamweaver changing path to site s reference instead of local

I have noticed recently, when I apply a template to a new HTML website, all the relative paths are pointed to my local files, example: file:///C|/webstuff/files but I cannot set them to relative paths ...

WPF ListView : Header styling

I want to have a ListView with columns and a particular style: The background for ALL column headers should be transparent except when the mouse is over in one of them. When this happends, the ...