0

How to create a New Custom Email Header Template in magento2 and load it into the emails? How to create multiple headers.

3 Answers 3

0
  1. Marketing -> Email Templates -> Add New Template
  2. Load Default Template "Magento_Email:Header"
  3. Edit "Template Content" and save template as "custom_header"
  4. Content -> Design - Configuration
  5. Open "Global" configuration
  6. Transactional Emails -> Header Template: select "custom_header"
0

Go to

Marketing -> Email Templates -> Add New Template

and load any default templates from drop-down there

Edit "Template Content" and save template as "custom_email_template"

then open the "Global Configuration" inside:

Content -> Design - Configuration

Choose

Transactional Emails -> Header Template: select "custom_email_template"

You are good to go. Please accept kudos as a solution.

0

Working Code

etc/email_templates.xml

<template id="design_custom_email_header_template" label="Custom Header" file="header-custom.html" type="html" module="[VENDOR_MODULE]" area="frontend"/>

etc/config.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
        <design>
            <custom_email>
                <header_template>design_custom_email_header_template</header_template>
            </custom_email>
        </design>
    </default>
</config>

etc/adminhtml/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <virtualType name="Magento\Config\Model\Config\Source\Email\Template\Header" type="Magento\Config\Model\Config\Source\Email\Template">
        <arguments>
            <argument name="data" xsi:type="array">
                <item name="path" xsi:type="string">design/custom_email/header_template</item>
            </argument>
        </arguments>
    </virtualType>
</config>

view/frontend/email/header-custom.html

<!--@subject {{trans "Header"}} @-->
<!--@vars {
"var logo_url":"Email Logo Image URL",
"var logo_alt":"Email Logo Alt Text",
"var logo_height":"Email Logo Image Height",
"var logo_width":"Email Logo Image Width",
"var template_styles|raw":"Template CSS"
} @-->

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Welcome To {{var logo_alt}}</title>
</head>
<body style="margin: 0 auto; /*height: 11.7in;*/ width: 8.3in;">
    <h5>Header</h5>
    <header>
        <table>
            <tr>
                <td><img src="{{var logo_url}}" alt=""
                        style=" width: 7rem; height: 2rem; "></td>
            </tr>
        </table>
    </header>

Use the below code to load the custom header in the template

{{template config_path="design/custom_email/header_template"}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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