18

I see in transactional email New order template, there is this tag that calls the header html file which is in app/locale/en_US/template/email/html

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

I wish to create a new header so I created new file app/local/en_US/template/email/html/header2.html and use code

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

but it does not work. With this code, no header is included in the email. Any ideas why or what is the proper way to create a custom email header?

  • 1
    do you have a header defined under the config path design/email/header2 – David Manners May 14 '15 at 4:54
  • Yes, I do. I believe the correct path is. app/local/en_US/template/email/html/header2.html. – Justin Lok May 14 '15 at 17:24
2

You can also implement the class default Magento to work with multiple (headers and footers).

Create file:

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;
    }

}

Then in your custom module, you can use as in the following example in your 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>

So you have these options to select from:

System > Configuration > Design > Transactional Email

1

This may help explain it:
Use multiple footers for email

What they ask:

Use multiple footers for email

up vote 1 down vote favorite Is it possible to use multiple footers for the Transactional Emails?

So I want to use a specific footer for a new order email, and an other footer for the shipment email.

I currently load the footer with this line: {{template config_path="design/email/footer"}}

How can I load a specific template in the transactional email?

1

design/email/header This refers to the configuration option NOT the template.

You could create a new module to add the option like so.

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

Alternatively just create a new CMS static block and then insert it on top of your email content like so.

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

Replacing.

{{template config_path="design/email/header"}}
  • I needed to allow cms/block under System -> Permissions -> blocks – Collin Anderson Oct 20 '17 at 20:26
1

Also you need to modify code in 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>

Instead of doing this in core file, try to do this in your custom module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.