如何创建自定义电子邮件标题


18

我在交易电子邮件“新订单”模板中看到,有一个标签可以调用位于 app/locale/en_US/template/email/html

{{template config_path="design/email/header"}}

我希望创建一个新的标头,所以我创建了新文件app/local/en_US/template/email/html/header2.html并使用代码

{{template config_path="design/email/header2"}}

但它不起作用。使用此代码,电子邮件中不包含标题。任何想法为什么或创建自定义电子邮件标题的正确方法是什么?


1
你有没有配置路径下定义的标题design/email/header2
大卫礼仪

是的,我愿意。我相信正确的道路是。app / local / en_US / template / email / html / header2.html。
贾斯汀·乐

Answers:


2

您还可以实现类默认的Magento以与多个(页眉和页脚)一起使用。

创建文件:

app / local / Mage / Adminhtml / Model / System / Config / Source / Email / Template.php

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    Mage
 * @package     Mage_Adminhtml
 * @copyright  Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */


/**
 * Adminhtml config system template source
 *
 * @category   Mage
 * @package    Mage_Adminhtml
 * @author      Magento Core Team <core@magentocommerce.com>
 */
class Mage_Adminhtml_Model_System_Config_Source_Email_Template extends Varien_Object
{
    /**
     * Config xpath to email template node
     *
     */
    const XML_PATH_TEMPLATE_EMAIL = 'global/template/email/';

    /**
     * Generate list of email templates
     *
     * @return array
     */
    public function toOptionArray()
    {
        if(!$collection = Mage::registry('config_system_email_template')) {
            $collection = Mage::getResourceModel('core/email_template_collection')
            ->load();

            Mage::register('config_system_email_template', $collection);
        }
        $options = $collection->toOptionArray();
        $templateName = Mage::helper('adminhtml')->__('Default Template from Locale');
        $nodeName = str_replace('/', '_', $this->getPath());

        // Implementation for various templates config.
        $templatesNodes = Mage::app()->getConfig()->getNode('global/template/email');
        if(count($templatesNodes)) {
            foreach($templatesNodes as $nodes) {
                foreach($nodes as $code => $config) {
                    if(strpos($code, $nodeName) !== false) {
                        $templateLabelNode = Mage::app()->getConfig()->getNode(self::XML_PATH_TEMPLATE_EMAIL . $code . '/label');
                        if ($templateLabelNode) {
                            $templateName = Mage::helper('adminhtml')->__((string)$templateLabelNode);
                            $templateName = Mage::helper('adminhtml')->__('%s (Default Template from Locale)', $templateName);
                        }
                        array_unshift(
                            $options,
                            array(
                                'value'=> str_replace('/', '_', $code),
                                'label' => $templateName
                                )
                            );
                    }
                }
            }
        }

        return $options;
    }

}

然后,在自定义模块中,可以在config.xml中的以下示例中使用:

<global>
    <template>
            <email>
                <design_email_header_custom_black translate="label" module="custom_module">
                    <label>Email - Header (CUSTOM BLACK)</label>
                    <file>html/header-custom-black.html</file>
                    <type>text</type>
                </design_email_header_custom_black>
                <design_email_header_custom_white translate="label" module="custom_module">
                    <label>Email - Header (CUSTOM WHITE)</label>
                    <file>html/header-custom-white.html</file>
                    <type>text</type>
                </design_email_header_custom_white>
                <design_email_footer_custom_black translate="label" module="custom_module">
                    <label>Email - Footer (CUSTOM BLACK)</label>
                    <file>html/footer-custom-black.html</file>
                    <type>text</type>
                </design_email_footer_custom_black>
                <design_email_footer_custom_white translate="label" module="custom_module">
                    <label>Email - Footer (CUSTOM WHITE)</label>
                    <file>html/footer-custom-white.html</file>
                    <type>text</type>
                </design_email_footer_custom_white>
            </email>
        </template>
</global>

因此,您可以从以下选项中进行选择:

系统>配置>设计>交易电子邮件


1

这可能有助于解释它:
使用多个页脚发送电子邮件

他们要求什么:

使用多个页脚发送电子邮件

赞成1赞成1赞成不赞成交易电子邮件可以使用多个页脚吗?

因此,我想为新订单电子邮件使用特定的页脚,为装运电子邮件使用其他页脚。

我目前在此行中加载页脚:{{template config_path =“ design / email / footer”}}

如何在交易电子邮件中加载特定模板?


1

设计/电子邮件/标题这是指配置选项,而不是模板。

您可以创建一个新模块来添加该选项,如下所示。

<config>
    <sections>
        <design>
            <groups>
                <email>
                    <fields>
                        <header2 translate="label">
                            <label>Email Header Template 2</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_email_template</source_model>
                            <sort_order>30</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </header2>

或者,只需创建一个新的CMS静态块,然后将其插入电子邮件内容的顶部即可。

{{block type="cms/block" block_id="email-header-sales" }}

正在更换。

{{template config_path="design/email/header"}}

我需要cms/block在“系统”->“权限”->“块”下允许
Collin Anderson,2010年

1

另外,您需要在 app/code/core/Mage/Core/etc/config.xml

<global>
    <template>
            <email>
                <design_email_header translate="label" module="core">
                    <label>Email - Header</label>
                    <file>html/header2.html(your file name)</file>
                    <type>text</type>
                </design_email_header>

与其在核心文件中执行此操作,不如在自定义模块中执行此操作。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.